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

fix($location): default to / for the url base if no base[href] #2969

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,12 @@ function $LocationProvider(){
function( $rootScope, $browser, $sniffer, $rootElement) {
var $location,
LocationMode,
baseHref = $browser.baseHref(),
baseHref = $browser.baseHref(), // if base[href] is undefined, it defaults to ''
initialUrl = $browser.url(),
appBase;

if (html5Mode) {
appBase = baseHref ? serverBase(initialUrl) + baseHref : initialUrl;
appBase = serverBase(initialUrl) + (baseHref || '/');
LocationMode = $sniffer.history ? LocationHtml5Url : LocationHashbangInHtml5Url;
} else {
appBase = stripHash(initialUrl);
Expand Down
13 changes: 13 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,19 @@ describe('$location', function() {
}
);
});


it('should set appBase to serverBase if base[href] is missing', function() {
initService(true, '!', true);
inject(
initBrowser('http://domain.com/my/view1#anchor1', ''),
function($rootScope, $location, $browser) {
expect($browser.url()).toBe('http://domain.com/my/view1#anchor1');
expect($location.path()).toBe('/my/view1');
expect($location.hash()).toBe('anchor1');
}
);
});
});


Expand Down