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

fix($browser): cookiePath now defaults to '' when basePath is undefined #1910

Closed
wants to merge 4 commits 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
2 changes: 1 addition & 1 deletion src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function Browser(window, document, $log, $sniffer) {
*/
self.baseHref = function() {
var href = baseElement.attr('href');
return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : href;
return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : '';
};

//////////////////////////////////////////////////////////////
Expand Down
16 changes: 14 additions & 2 deletions test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ describe('browser', function() {
});
});

describe('put via cookies(cookieName, string), if no <base href> ', function () {
beforeEach(function () {
fakeDocument.basePath = undefined;
});

it('should default path in cookie to \'\'(empty string)', function () {
browser.cookies('cookie', 'bender');
// This only fails in Safari and IE when cookiePath returns undefined
// Where it now succeeds since baseHref return '' instead of undefined
expect(document.cookie).toEqual('cookie=bender');
});
});

describe('get via cookies()[cookieName]', function() {

Expand Down Expand Up @@ -555,9 +567,9 @@ describe('browser', function() {
expect(browser.baseHref()).toEqual('/base/path/');
});

it('should return undefined if no <base href>', function() {
it('should return \'\' (empty string) if no <base href>', function() {
fakeDocument.basePath = undefined;
expect(browser.baseHref()).toBeUndefined();
expect(browser.baseHref()).toEqual('');
});

it('should remove domain from <base href>', function() {
Expand Down