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

fix() apostrophe in url #16098

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -228,6 +227,7 @@ function Browser(window, document, $log, $sniffer) {
forEach(urlChangeListeners, function(listener) {
listener(self.url(), cachedState);
});

}

/**
Expand Down
73 changes: 73 additions & 0 deletions test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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&param2=data%27s2';
$rootScope.$digest();
expect($location.path()).toBe('/param1=data\'s1&param2=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&param2=data%27s2';
$rootScope.$digest();
expect($location.path()).toBe('/param1=data\'s1&param2=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&param2=data%27s2';
$rootScope.$digest();
expect($location.path()).toBe('/param1=data\'s1&param2=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&param2=data%27s2';
$rootScope.$digest();
expect($location.path()).toBe('/param1=data\'s1&param2=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() {
Expand Down