-
Notifications
You must be signed in to change notification settings - Fork 27.4k
refactor(location): $location now uses urlUtils, not RegEx #3533
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Thanks, @mary-poppins. I shortened my message lines. |
@@ -30,7 +30,7 @@ function $HttpBackendProvider() { | |||
}]; | |||
} | |||
|
|||
function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was removed when @mhevery and I were pairing, just because it is not used anywhere. Maybe it should be a separate PR?
obj.$$protocol = match[1]; | ||
obj.$$host = match[3]; | ||
obj.$$port = int(match[5]) || DEFAULT_PORTS[match[1]] || null; | ||
obj.$$protocol = match.protocol? match.protocol.replace(/:$/,'') : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add a space before "?" for consistency.
CI is happy: http://ci.angularjs.org/job/angular.js-jeff/47/ |
@IgorMinar I updated the documentation annotation in urlUtils.js. |
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.
@IgorMinar I rebased the branch and made a couple of changes, seen in this commit: jeffbcross@278c342 Changes:
CI build was successful: http://ci.angularjs.org/job/angular.js-jeff/72/ |
@IgorMinar I am going to make a small change to the createHttpBackend method to make the implementation similar to what it was before this refactor. |
I made a small style change to make the createHttpBackend signature match the pre-refactor signature. This should be ready to review, @IgorMinar . |
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, which 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.
Todo