Problem/Motivation
Fuzzing reveals that UrlHelper::parse() throws a warning when called with some malformed strings:
WARNING Undefined array key 1 in core/lib/Drupal/Component/Utility/UrlHelper.php on line 200.
Steps to reproduce
\Drupal\Component\Utility\UrlHelper::parse('#/://#')
Proposed resolution
One solution could be to check if $parts[0] is empty before trying to use it in explode().
Issue fork drupal-3442833
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
vivek panicker commentedComment #5
vivek panicker commentedTests are failing because of media_library test https://git.drupalcode.org/issue/drupal-3442833/-/jobs/1413833#L79.
Not sure how to resolve it.
Comment #6
smustgrave commentedCurrent development branch is 11.x
Can't just add this though it will have to have backward compatibility coverage for the typehint being added. With a deprecation.
Comment #7
prudloff commentedThe type hint would not fix the issue.
You can see in the steps to reproduce that I am passing a string.
Comment #10
binoli lalani commentedHello,
I can reproduce the error in drupal 11.x and raised MR against 11.x branch. Please review.
Thank you!
Comment #11
smustgrave commentedSince this is a component class believe we will need test coverage
Comment #12
binoli lalani commentedHello @smustgrave,
Thank you for reviewing the code. I have added test coverage for the warning. Please review.
Thank you!
Comment #13
smustgrave commentedNot 100% the use case but the test does show the failure
And checking if empty doesn't seem to hurt. LGTM.
Comment #14
alexpottLeft a suggestion on the MR to preserve the logic of which bit of logic processes external urls and which processes internal.
Comment #17
prudloff commentedI believe @alexpott's comment have been addressed.
Comment #18
smustgrave commentedFeedback appears to be addressed
Comment #24
longwaveBackported down to 10.4.x as an eligible bug fix.
Committed and pushed 9307769b8b1 to 11.x and 56da864154b to 11.1.x and 4bf739cf9e9 to 10.5.x and ea023626eaa to 10.4.x. Thanks!