From b55ac177f750a594aadeb16c5dc1b85f07a02d03 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Tue, 28 Nov 2017 14:21:25 +0000 Subject: [PATCH] fix($location): decode non-component special chars in Hashbang URLS Fixes https://github.com/angular/angular.js/pull/16316#issuecomment-347527097 --- src/ng/location.js | 2 +- test/ng/locationSpec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ng/location.js b/src/ng/location.js index 184428883090..625b9297720d 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -422,7 +422,7 @@ var locationPrototype = { } var match = PATH_MATCH.exec(url); - if (match[1] || url === '') this.path(decodeURI(match[1])); + if (match[1] || url === '') this.path((this.$$html5 ? decodeURI : decodeURIComponent)(match[1])); if (match[2] || match[1] || url === '') this.search(match[3] || ''); this.hash(match[5] || ''); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index dd48edbe4e52..af17a1e3db76 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -673,6 +673,20 @@ describe('$location', function() { locationUrl.search({'q': '4/5 6'}); expect(locationUrl.absUrl()).toEqual('http://host.com?q=4%2F5%206'); }); + + it('url() should decode non-component special characters in hashbang mode', function() { + var locationUrl = new LocationHashbangUrl('http://host.com', 'http://host.com'); + locationUrl.$$parse('http://host.com'); + locationUrl.url('/foo%3Abar'); + expect(locationUrl.path()).toEqual('/foo:bar'); + }); + + it('url() should not decode non-component special characters in html5 mode', function() { + var locationUrl = new LocationHtml5Url('http://host.com', 'http://host.com'); + locationUrl.$$parse('http://host.com'); + locationUrl.url('/foo%3Abar'); + expect(locationUrl.path()).toEqual('/foo%3Abar'); + }); }); });