Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 15, 2020
Merged

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

merged 2 commits into from
Apr 15, 2020

Conversation

Werelds
Copy link
Contributor

@Werelds Werelds commented Apr 15, 2020

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
Contributor

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

@GrahamCampbell
Copy link
Member

This fix has now been released.

@Werelds
Copy link
Contributor Author

Werelds commented Apr 16, 2020

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