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

Commit

Permalink
fix($browser): normalize inputted URLs
Browse files Browse the repository at this point in the history
Fixes #16100
Fixes #16592
  • Loading branch information
jbedard committed Jun 22, 2018
1 parent 91f243b commit e47f077
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/ng/browser.js
Expand Up @@ -131,6 +131,15 @@ function Browser(window, document, $log, $sniffer) {
// setter
if (url) {
var sameState = lastHistoryState === state;
var hasTrailingSlash = url[url.length - 1] === '/';

// Normalize the inputted URL
url = urlResolve(url).href;

// ... but keep the (lack of) trailing '/' consistent
if (!hasTrailingSlash && url[url.length - 1] === '/') {
url = url.slice(0, url.length - 1);
}

// 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.
Expand Down
2 changes: 1 addition & 1 deletion test/ng/browserSpecs.js
Expand Up @@ -1013,7 +1013,7 @@ describe('browser', function() {
it('should not interfere with legacy browser url replace behavior', function() {
inject(function($rootScope) {
var current = fakeWindow.location.href;
var newUrl = 'notyet';
var newUrl = 'http://notyet';
sniffer.history = false;
expect(historyEntriesLength).toBe(1);
browser.url(newUrl, true);
Expand Down

0 comments on commit e47f077

Please sign in to comment.