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

Use updated dperini's url regex #153

Closed
huan086 opened this issue Aug 29, 2016 · 6 comments
Closed

Use updated dperini's url regex #153

huan086 opened this issue Aug 29, 2016 · 6 comments
Labels
bug
Milestone

Comments

@huan086
Copy link

@huan086 huan086 commented Aug 29, 2016

dperini updated the gist

old code

          "(?!10(?:\\.\\d{1,3}){3})" +
          "(?!127(?:\\.\\d{1,3}){3})" +
          "(?!169\\.254(?:\\.\\d{1,3}){2})" +
          "(?!192\\.168(?:\\.\\d{1,3}){2})" +

...

          // path
          "(?:\\/[^\\s]*)?" +

new code

      "(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
...
    // resource path
"(?:[/?#]\\S*)?" +

major change is that http://example.com?query and http://example.com#query used to be detected as invalid (that's bad), while the new regex allows them

@ansman
Copy link
Owner

@ansman ansman commented Aug 29, 2016

Can you show a case where the existing validate.js code doesn't work?

Both queries and fragments work: https://github.com/ansman/validate.js/blob/master/specs/validators/url-spec.js#L73

@huan086
Copy link
Author

@huan086 huan086 commented Aug 30, 2016

http://example.com/path?query works, but http://example.com?query doesn't. dperini's updated gist fixes that

@ansman ansman closed this in cffa61a Aug 31, 2016
@ansman
Copy link
Owner

@ansman ansman commented Aug 31, 2016

Got it, thanks.

@ansman ansman added the bug label Aug 31, 2016
@ansman ansman added this to the Next milestone Aug 31, 2016
@huan086
Copy link
Author

@huan086 huan086 commented Sep 1, 2016

Oh wait, I realized that's not all.

Hostname match is now

(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)

instead of

(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)

which solves the catastrophic backtracking problem by removing the +, and also supports http://g--a.com

It would be wise to update the entire regex in order to get all the fixes

@ansman
Copy link
Owner

@ansman ansman commented Sep 6, 2016

Done

@ansman
Copy link
Owner

@ansman ansman commented Nov 5, 2016

Released in 0.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.