From ba5f5a5eb767d5112ee2a0cb6489351777d62aab Mon Sep 17 00:00:00 2001 From: dmartres Date: Tue, 11 Jul 2017 15:00:39 -0300 Subject: [PATCH] fix() apostrophe in url --- src/ng/browser.js | 4 +-- test/ng/browserSpecs.js | 73 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/ng/browser.js b/src/ng/browser.js index 3f5f125ed4c3..b87329a3b73c 100644 --- a/src/ng/browser.js +++ b/src/ng/browser.js @@ -132,7 +132,6 @@ function Browser(window, document, $log, $sniffer) { // setter if (url) { var sameState = lastHistoryState === state; - // Don't change anything if previous and current URLs and states match. This also prevents // IE<10 from getting into redirect loop when in LocationHashbangInHtml5Url mode. // See https://github.com/angular/angular.js/commit/ffb2701 @@ -219,7 +218,7 @@ function Browser(window, document, $log, $sniffer) { var prevLastHistoryState = lastHistoryState; cacheState(); - if (lastBrowserUrl === self.url() && prevLastHistoryState === cachedState) { + if (lastBrowserUrl.replace(/%27/g, '\'') === self.url() && prevLastHistoryState === cachedState) { return; } @@ -228,6 +227,7 @@ function Browser(window, document, $log, $sniffer) { forEach(urlChangeListeners, function(listener) { listener(self.url(), cachedState); }); + } /** diff --git a/test/ng/browserSpecs.js b/test/ng/browserSpecs.js index 074e4404830a..915d266a63d7 100644 --- a/test/ng/browserSpecs.js +++ b/test/ng/browserSpecs.js @@ -879,6 +879,79 @@ describe('browser', function() { }); }); + + it('apostrophes are supported in url with no history support, no html5Mode', function() { + + setup({ + history: false, + html5Mode: false + }); + + inject(function($rootScope, $location) { + /* all aphostrofes in url should be replaced */ + fakeWindow.location.href = 'http://server/#!/param1=data%27s1¶m2=data%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/param1=data\'s1¶m2=data\'s2'); + + /* validate that location.href could be updated */ + fakeWindow.location.href = 'http://server/#!/data1=anotherValue%27s1&data2=anotherValue%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/data1=anotherValue\'s1&data2=anotherValue\'s2'); + }); + + }); + + + it('apostrophes are supported in url with html5Mode and no history support', function() { + setup({ + history: false, + html5Mode: true + }); + + inject(function($rootScope, $location) { + + fakeWindow.location.href = 'http://server/#!/param1=data%27s1¶m2=data%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/param1=data\'s1¶m2=data\'s2'); + + fakeWindow.location.href = 'http://server/#!/data1=anotherValue%27s1&data2=anotherValue%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/data1=anotherValue\'s1&data2=anotherValue\'s2'); + }); + + }); + + it('apostrophes are supported in url with history and no html5', function() { + setup({ + history: true, + html5Mode: false + }); + inject(function($rootScope, $location) { + fakeWindow.location.href = 'http://server/#!/param1=data%27s1¶m2=data%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/param1=data\'s1¶m2=data\'s2'); + fakeWindow.location.href = 'http://server/#!/data1=anotherValue%27s1&data2=anotherValue%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/data1=anotherValue\'s1&data2=anotherValue\'s2'); + }); + }); + + it('apostrophes are supported in url with history and html5', function() { + setup({ + history: true, + html5Mode: true + }); + inject(function($rootScope, $location) { + fakeWindow.location.href = 'http://server/param1=data%27s1¶m2=data%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/param1=data\'s1¶m2=data\'s2'); + fakeWindow.location.href = 'http://server/data1=anotherValue%27s1&data2=anotherValue%27s2'; + $rootScope.$digest(); + expect($location.path()).toBe('/data1=anotherValue\'s1&data2=anotherValue\'s2'); + }); + + }); + }); it('should not reload the page on every $digest when the page will be reloaded due to url rewrite on load', function() {