Skip to content

[6.x] Fix a regression caused by #32315#32388

Merged
taylorotwell merged 2 commits into
laravel:6.xfrom
Werelds:fix/regression-32315
Apr 15, 2020
Merged

[6.x] Fix a regression caused by #32315#32388
taylorotwell merged 2 commits into
laravel:6.xfrom
Werelds:fix/regression-32315

Conversation

@Werelds

@Werelds Werelds commented Apr 15, 2020

Copy link
Copy Markdown
Contributor

This fixes a regression caused by #32315, in which the regular expression was updated based on Symfony's Validator, but in doing so percent signs were copied across incorrectly. As a result, some valid URLs are now being reported as invalid. An example URL would be https://domain.com/path/%2528failed%2526?param=1#fragment; admittedly, this is wrongly encoded, but that is kind of the point, as it is not technically invalid. I've added this URL to the test too.

Symfony runs their regular expression through sprintf(), so the double-encoded percent signs (%%) come out of that as single ones (%).

This PR rectifies that. I generated the updated regular expression by running the whole thing through sprintf() like Symfony would've, but with Laravel's fixed set of protocols.

I've set the target to 6.x as this is a clear bug fix that should go into 6.x and 7.x alike.

@Werelds Werelds changed the title Fixes a regression caused by #32315 Fix a regression caused by #32315 Apr 15, 2020
@GrahamCampbell GrahamCampbell changed the title Fix a regression caused by #32315 [6.x] Fix a regression caused by #32315 Apr 15, 2020
@taylorotwell taylorotwell merged commit 2b3dd8c into laravel:6.x Apr 15, 2020
@bsacharski

Copy link
Copy Markdown
Contributor

@Werelds good catch, thanks for fixing the issue and sorry for causing trouble.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

This fix has now been released.

@Werelds

Werelds commented Apr 16, 2020

Copy link
Copy Markdown
Contributor Author

Thanks @GrahamCampbell!

@bsacharski took me a while to spot it as well. When I looked at the regex directly I didn't spot it, I eventually resorted to running a diff between your version and Symfony's version, with all protocols except https removed for comparison. That's when I finally spotted it.

I think we all have a strong love/hate relationship with regular expressions :D

bsacharski referenced this pull request Apr 16, 2020
…32315)

The regex used by url validation logic was previously derived from version
2.7.4 of Symfony Validator component. As it turns out, old regex had a bug
where it wouldn't accept urls where domain was a hostname ending with a digit.
As such, the urls like http://domain1/ would be considered as invalid.

To fix this issue I've updated \Illuminate\Validation\Concerns\ValidatesAttributes::validateUrl
method using regex derived from version 5.0.7 of the Symfony Validator component.
To make sure that the fix works, new test cases were also added.

Co-authored-by: Bartlomiej Sacharski <bartlomiej@cementownia.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants