Skip to content

Commit b0e5ac6

Browse files
committed
fix($browser): normalize inputted URLs
Fixes angular#16100
1 parent 87a586e commit b0e5ac6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/ng/browser.js

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ function Browser(window, document, $log, $sniffer) {
133133
if (url) {
134134
var sameState = lastHistoryState === state;
135135

136+
// Normalize the inputted URL
137+
url = urlResolve(url).href;
138+
136139
// Don't change anything if previous and current URLs and states match. This also prevents
137140
// IE<10 from getting into redirect loop when in LocationHashbangInHtml5Url mode.
138141
// See https://github.com/angular/angular.js/commit/ffb2701

test/ng/browserSpecs.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('browser', function() {
296296
browser.url('http://new.org');
297297

298298
expect(pushState).toHaveBeenCalledOnce();
299-
expect(pushState.calls.argsFor(0)[2]).toEqual('http://new.org');
299+
expect(pushState.calls.argsFor(0)[2]).toEqual('http://new.org/');
300300

301301
expect(replaceState).not.toHaveBeenCalled();
302302
expect(locationReplace).not.toHaveBeenCalled();
@@ -308,7 +308,7 @@ describe('browser', function() {
308308
browser.url('http://new.org', true);
309309

310310
expect(replaceState).toHaveBeenCalledOnce();
311-
expect(replaceState.calls.argsFor(0)[2]).toEqual('http://new.org');
311+
expect(replaceState.calls.argsFor(0)[2]).toEqual('http://new.org/');
312312

313313
expect(pushState).not.toHaveBeenCalled();
314314
expect(locationReplace).not.toHaveBeenCalled();
@@ -319,7 +319,7 @@ describe('browser', function() {
319319
sniffer.history = false;
320320
browser.url('http://new.org');
321321

322-
expect(fakeWindow.location.href).toEqual('http://new.org');
322+
expect(fakeWindow.location.href).toEqual('http://new.org/');
323323

324324
expect(pushState).not.toHaveBeenCalled();
325325
expect(replaceState).not.toHaveBeenCalled();
@@ -352,7 +352,7 @@ describe('browser', function() {
352352
sniffer.history = false;
353353
browser.url('http://new.org', true);
354354

355-
expect(locationReplace).toHaveBeenCalledWith('http://new.org');
355+
expect(locationReplace).toHaveBeenCalledWith('http://new.org/');
356356

357357
expect(pushState).not.toHaveBeenCalled();
358358
expect(replaceState).not.toHaveBeenCalled();
@@ -945,7 +945,7 @@ describe('browser', function() {
945945
it('should not interfere with legacy browser url replace behavior', function() {
946946
inject(function($rootScope) {
947947
var current = fakeWindow.location.href;
948-
var newUrl = 'notyet';
948+
var newUrl = 'http://notyet/';
949949
sniffer.history = false;
950950
expect(historyEntriesLength).toBe(1);
951951
browser.url(newUrl, true);

0 commit comments

Comments
 (0)