Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
On PHP 8 we need to ensure that the fragment is not set to an empty string. See the behaviour change https://3v4l.org/HsvX0
https://github.com/php/php-src/blob/master/UPGRADING#L430
Without this fix
// Ensure an empty fragment of # in the URI is discarded as expected.
[
'entity:test_entity/1#',
[],
'entity.test_entity.canonical',
['test_entity' => '1'],
NULL,
NULL,
],
from \Drupal\Tests\Core\UrlTest::providerTestEntityUris() will fail.
Proposed resolution
To maintain PHP 7 behaviour we need to check the value before setting it.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
None
Comment | File | Size | Author |
---|---|---|---|
#2 | 3156883-2.patch | 654 bytes | alexpott |
Comments
Comment #2
alexpottComment #3
alexpottComment #4
alexpottSo we're doing things to match the PHP 7 behaviour. Interesting. I wonder what's the right thing to do here. The patch in #2 makes \Drupal\Core\Url::fromUri() behave the same way on PHP 7 & 8. I guess that's the best thing to do.
Comment #5
catchRemoving the fragment seems fine to me and preserves existing behaviour. If for some reason we wanted to change it, I think it'd be fine to just open a new issue (and that issue could deal with the PHP 7 vs. 8 compatibility, or not if we've dropped PHP 7 by then).
Comment #6
longwaveRTBC+1, an empty fragment makes no difference so removing it seems fine for now if it keeps the behaviour the same.
Comment #8
catchCommitted d3f654b and pushed to 9.1.x. Thanks!
Comment #11
catchActually this is a straightforward one to backport, so even if we don't manage that for every PHP 8 issue, there's no reason not to. Cherry-picked to 9.0.x and 8.9.x too.
Comment #12
alexpottComment #14
solideogloria CreditAttribution: solideogloria commentedI'm curious, why was this changed? An href needs to be non-empty for a link to work, and in HTML an href with an empty fragment of
#
should be used if the link is something to open a modal, for example.See these questions of people trying to find workarounds.
https://drupal.stackexchange.com/q/229877
https://drupal.stackexchange.com/q/231491