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

Commit 7090924

Browse files
fredrikbonanderIgorMinar
authored andcommitted
fix($cookies): set cookies on Safari&IE when base[href] is undefined
Safari and IE don't like being told to store cookies with path set to undefined. This change ensures that if base[href] (from which cookie path is derived) is undefined then the cookie path defaults to ''. The test verifies that the cookie is set instead of checking that cookie has correct path, this is due to that cookie meta information is not avabile once the cookie is set. Closes #1190, #1191
1 parent df744f3 commit 7090924

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/ng/browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function Browser(window, document, $log, $sniffer) {
237237
*/
238238
self.baseHref = function() {
239239
var href = baseElement.attr('href');
240-
return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : href;
240+
return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : '';
241241
};
242242

243243
//////////////////////////////////////////////////////////////

test/ng/browserSpecs.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ describe('browser', function() {
279279
});
280280
});
281281

282+
describe('put via cookies(cookieName, string), if no <base href> ', function () {
283+
beforeEach(function () {
284+
fakeDocument.basePath = undefined;
285+
});
286+
287+
it('should default path in cookie to "" (empty string)', function () {
288+
browser.cookies('cookie', 'bender');
289+
// This only fails in Safari and IE when cookiePath returns undefined
290+
// Where it now succeeds since baseHref return '' instead of undefined
291+
expect(document.cookie).toEqual('cookie=bender');
292+
});
293+
});
282294

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

@@ -555,9 +567,9 @@ describe('browser', function() {
555567
expect(browser.baseHref()).toEqual('/base/path/');
556568
});
557569

558-
it('should return undefined if no <base href>', function() {
570+
it('should return \'\' (empty string) if no <base href>', function() {
559571
fakeDocument.basePath = undefined;
560-
expect(browser.baseHref()).toBeUndefined();
572+
expect(browser.baseHref()).toEqual('');
561573
});
562574

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

0 commit comments

Comments
 (0)