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

fix($location): allow empty string URLs to reset path, search, and hash #10064

Closed
wants to merge 1 commit into from

Conversation

NevilleS
Copy link
Contributor

Currently, providing '' to $location#url will only reset the hash, but otherwise has no effect. This
change brings the behaviour of $location#url more inline with window.location.href, which when
assigned to an empty string loads the page's base href.

Before:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.com/path

After:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.com

Fixes #10063

Currently, providing '' to $location#url will only reset the hash, but otherwise has no effect. This
change brings the behaviour of $location#url more inline with window.location.href, which when
assigned to an empty string loads the page's base href.

Before:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.com/path

After:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.com

Fixes angular#10063
@NevilleS
Copy link
Contributor Author

This is very basic, and I tested to see that it behaves as I'd expect to, but... after digging in a bit more I realized that $location.url('') doesn't quite do nothing, it resets the hash. So this could potentially break applications that are using this behaviour (although probably not intentionally). I haven't marked it as a breaking change though, let me know what you guys think.

@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@NevilleS
Copy link
Contributor Author

@mary-poppins are you still broken? 😢

@pkozlowski-opensource
Copy link
Member

@NevilleS the test is good, left one minor comment. Don't feel too strong about it but I find the proposed version more readable. WDYT?

@pkozlowski-opensource
Copy link
Member

OK, cool, my comment is not valid really.

LGTM.

@NevilleS
Copy link
Contributor Author

Thanks. I'm still unsure whether this constitutes a breaking change:
previously using an empty string would only reset the hash, now it resets
path+search+hash. I believe this is the correct behaviour, but since it is
different, should it be flagged as breaking?
On Nov 15, 2014 11:41 AM, "Pawel Kozlowski" notifications@github.com
wrote:

OK, cool, my comment is not valid really.

LGTM.


Reply to this email directly or view it on GitHub
#10064 (comment).

@pkozlowski-opensource
Copy link
Member

Yes, technically it is a breaking change. At the same time if someone is using .url() to reset the hash-part only I would say that this is incorrect usage of the API. In this sense I think this breaking change is fixing a bug that shouldn't be here in the first place. So I don't think I should mark it as a breaking change.

@pkozlowski-opensource
Copy link
Member

@NevilleS did you sign the CLA? There is a new bot that can verify a signature but you need to update your CLA with the GitHub user name: http://angularjs.blogspot.fr/2014/11/angular-cla-infrastructure-changes.html

@NevilleS
Copy link
Contributor Author

Yes, I have. Hopefully @googlebot will agree... (bump bump)

@googlebot
Copy link

CLAs look good, thanks!

@pkozlowski-opensource
Copy link
Member

Cool, thnx @NevilleS. Merging.

@NevilleS
Copy link
Contributor Author

👍 happy to help

@NevilleS NevilleS deleted the accept-empty-string-url branch November 22, 2014 17:45
Roman-Didenko pushed a commit to Roman-Didenko/angular.js that referenced this pull request Mar 31, 2015
Currently, providing '' to $location#url will only reset the hash, but otherwise has no effect. This
change brings the behaviour of $location#url more inline with window.location.href, which when
assigned to an empty string loads the page's base href.

Before:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.com/path

After:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.com

Fixes angular#10063

Closes angular#10064
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.

$location.url has no effect when given an empty string
4 participants