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
If you create a Drupal\Core\Url
object using an external URL (e.g. 'http://drupal.org') and pass this into \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
it can cause an uncaught exception because $url->getInternalPath()
is called when $options['set_active_class']
is not empty.
Proposed resolution
don't call $url->getInternalPath()
for an external Url, and add a test case.
Comment | File | Size | Author |
---|---|---|---|
#7 | 2265913-7.patch | 2.5 KB | pwolanin |
#7 | increment.txt | 1.47 KB | pwolanin |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedHere's the fix, still needs an added test case.
downgrading to major, since I'm not sure this is called this way currently in core, but the code is clearly broken and caught me up in a patch.
Comment #2
pwolanin CreditAttribution: pwolanin commentedHere's the test alone (should have 1 fail), updated patch, and increment.
Also adds a small optimization to the Url class so we don't check again that the url is external.
not that I moved the $url->isExternal() check up a little since we shouldn't need any of the logic related to the active class for an external link.
Comment #3
tim.plunkettThis is a sign you should have a new test method. Can you just put that new test in
public function testGenerateFromUrlExternal()
?Comment #4
pwolanin CreditAttribution: pwolanin commentedSure.
Comment #5
pwolanin CreditAttribution: pwolanin commentedsmall wording fix.
Comment #7
pwolanin CreditAttribution: pwolanin commentedtim.plunkett suggests passing the external flag to the UrlGenerator should be put in a separate issue.
Comment #8
tim.plunkettExcellent, thanks
Comment #9
pwolanin CreditAttribution: pwolanin commentedComment #10
webchickCommitted and pushed to 8.x. Thanks!
Comment #12
catchDoes that issue exist?
Comment #13
pwolanin CreditAttribution: pwolanin commentedHere's the follow-up with initlal patch: #2266377: Speed up UrlGenerator a little by setting the 'external' option in the Url object