-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($location): support IPv6 addresses #2950
Conversation
PR Checklist (Minor Bugfix)
|
Just signed the CLA as Kien Chuan Chua. |
Made regex stricter and added more tests for valid IPv6 addresses. |
Thanks for the PR. @mhevery and I are looking at it, and are going to squash in some changes to the $location service to fall back on a private urlUtils service that falls back on browsers to parse URLs instead of RegEx. |
Sounds like a better way to go. Previously, I've used the HTMLAnchorElement
|
That's the approach $$UrlUtils uses as well. |
Sounds great. 👍 This PR would be unnecessary then. |
The tests are useful. |
I moved the refactoring effort into a new PR (#3533) since the effort was significant enough not to be amended to this commit. Closing. |
The location service, and other portions of the application, were relying on a complicated regular expression to get parts of a URL. But there is already a private urlUtils provider, which relies on HTMLAnchorElement to provide this information, and is suitable for most cases. In order to make urlUtils more accessible in the absence of DI, its methods were converted to standalone functions available globally. The urlUtils.resolve method was renamed urlResolve, and was refactored to only take 1 argument, url, and not the 2nd "parse" boolean. The method now always returns a parsed url. All places in code which previously wanted a string instead of a parsed url can now get the value from the href property of the returned object. Tests were also added to ensure IPv6 addresses were handled correctly. Closes angular#3533 Closes angular#2950 Closes angular#3249
The location service, and other portions of the application, were relying on a complicated regular expression to get parts of a URL. But there is already a private urlUtils provider, which relies on HTMLAnchorElement to provide this information, and is suitable for most cases. In order to make urlUtils more accessible in the absence of DI, its methods were converted to standalone functions available globally. The urlUtils.resolve method was renamed urlResolve, and was refactored to only take 1 argument, url, and not the 2nd "parse" boolean. The method now always returns a parsed url. All places in code which previously wanted a string instead of a parsed url can now get the value from the href property of the returned object. Tests were also added to ensure IPv6 addresses were handled correctly. Closes angular#3533 Closes angular#2950 Closes angular#3249
The location service, and other portions of the application, were relying on a complicated regular expression to get parts of a URL. But there is already a private urlUtils provider, which relies on HTMLAnchorElement to provide this information, and is suitable for most cases. In order to make urlUtils more accessible in the absence of DI, its methods were converted to standalone functions available globally. The urlUtils.resolve method was renamed urlResolve, and was refactored to only take 1 argument, url, and not the 2nd "parse" boolean. The method now always returns a parsed url. All places in code which previously wanted a string instead of a parsed url can now get the value from the href property of the returned object. Tests were also added to ensure IPv6 addresses were handled correctly. Closes angular#3533 Closes angular#2950 Closes angular#3249
Fixes #2864