Skip to content

Commit 1518c31

Browse files
committed
Specify path when setting cookies
1 parent 77970f7 commit 1518c31

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

dashboard/app/assets/javascripts/client_state.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ dashboard.clientState.EXPIRY_DAYS = 365;
3232
*/
3333
var MAX_LINES_TO_SAVE = 1000;
3434

35+
var COOKIE_OPTIONS = {expires: dashboard.clientState.EXPIRY_DAYS, path: '/'};
3536

3637
dashboard.clientState.reset = function() {
37-
$.removeCookie('progress');
38-
$.removeCookie('lines');
38+
$.removeCookie('progress', {path: '/'});
39+
$.removeCookie('lines', {path: '/'});
3940
};
4041

4142
/**
@@ -73,8 +74,7 @@ dashboard.clientState.trackProgress = function(result, lines, testResult, script
7374
function setLevelProgress(level, progress) {
7475
var progressMap = dashboard.clientState.allLevelsProgress();
7576
progressMap[String(level)] = progress;
76-
$.cookie('progress', JSON.stringify(progressMap),
77-
{expires: dashboard.clientState.EXPIRY_DAYS});
77+
$.cookie('progress', JSON.stringify(progressMap), COOKIE_OPTIONS);
7878
}
7979

8080
/**
@@ -107,7 +107,6 @@ dashboard.clientState.lines = function() {
107107
function addLines(addedLines) {
108108
var newLines = Math.min(dashboard.clientState.lines() + Math.max(addedLines, 0), MAX_LINES_TO_SAVE);
109109

110-
$.cookie('lines', String(newLines),
111-
{expires: dashboard.clientState.EXPIRY_DAYS});
110+
$.cookie('lines', String(newLines), COOKIE_OPTIONS);
112111
}
113112
})(window, $);

dashboard/spec/javascripts/client_state_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ describe("clientState#trackProgress", function() {
8080
it("handles malformed cookies", function () {
8181
var state = dashboard.clientState;
8282

83-
$.cookie('progress', '', 365);
83+
$.cookie('progress', '', {expires: 365, path: '/'});
8484
state.levelProgress(1).should.equal(0);
8585

86-
$.cookie('progress', '{\'malformed_json\':true', 365);
86+
$.cookie('progress', '{\'malformed_json\':true', {expires: 365, path: '/'});
8787
state.levelProgress(1).should.equal(0);
8888

8989
});

0 commit comments

Comments
 (0)