Skip to content

Commit

Permalink
[FIXED JENKINS-32074] When rootURL is empty, store cookies at '/'
Browse files Browse the repository at this point in the history
When Jenkins is running from the top-level URL, the rootURL variable is an empty
string. In this case, store the cookies at '/' instead of rootURL.

Prior to this change, the cookies were created with an empty path, and the
browser defaults to storing them at the build URL. These cookies will now be
deleted because they would override the cookies stored at the Jenkins URL.

Bug introduced by JENKINS-29899.
  • Loading branch information
StevenGBrown committed Jan 13, 2016
1 parent 409ae92 commit 26f6fdb
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -42,6 +42,12 @@ function init() {
'local': document.getElementById('timestamper-localTime')
};

// Delete cookies added with the wrong path by Timestamper 1.7.2. See JENKINS-32074.
var attributes = '; path=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
document.cookie = 'jenkins-timestamper=' + attributes;
document.cookie = 'jenkins-timestamper-local=' + attributes;
document.cookie = 'jenkins-timestamper-offset=' + attributes;

// Set the mode from a cookie or initialize it (also handle migrating old cookie values to new ones).
var mode = getCookie() || 'system';
if (mode == 'local') {
Expand Down Expand Up @@ -106,9 +112,13 @@ function setCookie(value, suffix) {
name += '-' + suffix;
}

var path = '/';
if (rootURL) {
path = rootURL;
}
var currentDate = new Date();
currentDate.setTime(currentDate.getTime() + 1000 * 60 * 60 * 24 * 365 * 2); // 2 years
var attributes = '; path=' + rootURL + '; expires=' + currentDate.toGMTString();
var attributes = '; path=' + path + '; expires=' + currentDate.toGMTString();
document.cookie = name + '=' + value + attributes;
}

Expand Down

0 comments on commit 26f6fdb

Please sign in to comment.