Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

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
Milestone

Comments

@huan086
Copy link

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 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 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 as completed in cffa61a Aug 31, 2016
@ansman
Copy link
Owner

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 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 commented Sep 6, 2016

Done

@ansman
Copy link
Owner

ansman commented Nov 5, 2016

Released in 0.11.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants