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

Commit 2c1e589

Browse files
fix($location): always decode special chars in $location.url(value)
The original fix for #16312 included changing how `$location.url(value)` decoded the special characters passed to it as a setter. This broke a number of use cases (mostly involving the ui-router). Further analysis appears to show that we can solve #16312, to prevent urls being rewritten with decoded values, without modifying the behaviour of `$location.url`. This commit reverts changes to `$location.url(value)` so that encoded chars will once again be decoded and passed to `$location.path(value)`. In particular it will convert encoded forward slashes, which changes how the path is updated, since e.g. `a/b/%2Fc%2Fd` will become `a/b/c/d`. While this is arguably not "correct", it appears that there are too many use cases relying upon this behaviour.
1 parent 6d5ef34 commit 2c1e589

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ var locationPrototype = {
422422
}
423423

424424
var match = PATH_MATCH.exec(url);
425-
if (match[1] || url === '') this.path((this.$$html5 ? decodeURI : decodeURIComponent)(match[1]));
425+
if (match[1] || url === '') this.path(decodeURIComponent(match[1]));
426426
if (match[2] || match[1] || url === '') this.search(match[3] || '');
427427
this.hash(match[5] || '');
428428

test/ng/locationSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,11 @@ describe('$location', function() {
681681
expect(locationUrl.path()).toEqual('/foo:bar');
682682
});
683683

684-
it('url() should not decode non-component special characters in html5 mode', function() {
684+
it('url() should decode non-component special characters in html5 mode', function() {
685685
var locationUrl = new LocationHtml5Url('http://host.com', 'http://host.com');
686686
locationUrl.$$parse('http://host.com');
687687
locationUrl.url('/foo%3Abar');
688-
expect(locationUrl.path()).toEqual('/foo%3Abar');
688+
expect(locationUrl.path()).toEqual('/foo:bar');
689689
});
690690
});
691691
});

0 commit comments

Comments
 (0)