Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

refactor(location): $location now uses urlUtils, not RegEx #3533

Closed
wants to merge 2 commits into from

Conversation

jeffbcross
Copy link
Contributor

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

  • Get this test passing in IE: $location HashbangUrl should not preserve old properties when parsing new url FAILED (returned URL does not have #!/ as expected)
  • Review all changes with Igor
  • Whatever Mary Poppins tells me

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@jeffbcross
Copy link
Contributor Author

Thanks, @mary-poppins. I shortened my message lines.

@@ -30,7 +30,7 @@ function $HttpBackendProvider() {
}];
}

function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) {
Copy link
Contributor Author

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(/:$/,'') : '';
Copy link
Contributor Author

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.

@jeffbcross
Copy link
Contributor Author

@jeffbcross
Copy link
Contributor Author

@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.
@jeffbcross
Copy link
Contributor Author

@IgorMinar I rebased the branch and made a couple of changes, seen in this commit: jeffbcross@278c342

Changes:

  • I changed the file protocol tests to only provide the protocol argument to createHttpBackend if it could not be inferred from the URL

CI build was successful: http://ci.angularjs.org/job/angular.js-jeff/72/

@jeffbcross
Copy link
Contributor Author

@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.

@jeffbcross
Copy link
Contributor Author

I made a small style change to make the createHttpBackend signature match the pre-refactor signature. This should be ready to review, @IgorMinar .

@ghost ghost assigned IgorMinar Oct 10, 2013
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
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
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants