Comparing version 2.1.3 to 2.1.4
{ | ||
"name": "js-cookie", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"description": "A simple, lightweight JavaScript API for handling cookies", | ||
@@ -33,6 +33,6 @@ "main": "src/js.cookie.js", | ||
"grunt-contrib-connect": "1.0.2", | ||
"grunt-contrib-jshint": "1.0.0", | ||
"grunt-contrib-jshint": "1.1.0", | ||
"grunt-contrib-nodeunit": "1.0.0", | ||
"grunt-contrib-qunit": "1.2.0", | ||
"grunt-contrib-uglify": "2.0.0", | ||
"grunt-contrib-qunit": "1.3.0", | ||
"grunt-contrib-uglify": "2.2.1", | ||
"grunt-contrib-watch": "1.0.0", | ||
@@ -43,4 +43,4 @@ "grunt-jscs": "3.0.1", | ||
"qunitjs": "1.23.1", | ||
"requirejs": "2.2.0" | ||
"requirejs": "2.3.3" | ||
} | ||
} |
@@ -97,2 +97,4 @@ <p align="center"> | ||
*Note: Removing unexisting cookie does not raise any exception nor return any value* | ||
## Namespace conflicts | ||
@@ -146,3 +148,3 @@ | ||
The only character in cookie-name or cookie-value that is allowed and still encoded is the percent `%` character, it is escaped in order to interpret percent input as literal. | ||
Please note that the default encoding/decoding strategy is meant to be interoperable [only between cookies that are read/written by js-cookie](https://github.com/js-cookie/js-cookie/pull/200#discussion_r63270778). To override the default encoding/decoding strategy you need to use a [converter](#converter). | ||
Please note that the default encoding/decoding strategy is meant to be interoperable [only between cookies that are read/written by js-cookie](https://github.com/js-cookie/js-cookie/pull/200#discussion_r63270778). To override the default encoding/decoding strategy you need to use a [converter](#converters). | ||
@@ -276,2 +278,6 @@ ## Cookie Attributes | ||
## Security | ||
For vulnerability reports, send an e-mail to `jscookie at gmail dot com` | ||
## Manual release steps | ||
@@ -285,5 +291,5 @@ | ||
* Change the `latest` tag pointer to the latest commit | ||
* `git tag -fa latest` | ||
* `git tag -f latest` | ||
* `git push <remote> :refs/tags/latest` | ||
* Commit with the message "Prepare for the next development iteration" | ||
* `git push origin master --tags` | ||
* Release on npm | ||
@@ -290,0 +296,0 @@ |
/*! | ||
* JavaScript Cookie v2.1.3 | ||
* JavaScript Cookie v2.1.4 | ||
* https://github.com/js-cookie/js-cookie | ||
@@ -59,2 +59,5 @@ * | ||
// We're using "expires" because "max-age" is not supported by IE | ||
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; | ||
try { | ||
@@ -78,9 +81,15 @@ result = JSON.stringify(value); | ||
return (document.cookie = [ | ||
key, '=', value, | ||
attributes.expires ? '; expires=' + attributes.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE | ||
attributes.path ? '; path=' + attributes.path : '', | ||
attributes.domain ? '; domain=' + attributes.domain : '', | ||
attributes.secure ? '; secure' : '' | ||
].join('')); | ||
var stringifiedAttributes = ''; | ||
for (var attributeName in attributes) { | ||
if (!attributes[attributeName]) { | ||
continue; | ||
} | ||
stringifiedAttributes += '; ' + attributeName; | ||
if (attributes[attributeName] === true) { | ||
continue; | ||
} | ||
stringifiedAttributes += '=' + attributes[attributeName]; | ||
} | ||
return (document.cookie = key + '=' + value + stringifiedAttributes); | ||
} | ||
@@ -87,0 +96,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/*global lifecycle: true*/ | ||
@@ -183,18 +185,33 @@ | ||
sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 21); | ||
var expected = 'c=v; expires=' + sevenDaysFromNow.toUTCString(); | ||
var actual = Cookies.set('c', 'v', { expires: 21 }).substring(0, expected.length); | ||
assert.strictEqual(actual, expected, 'should write the cookie string with expires'); | ||
var expected = 'expires=' + sevenDaysFromNow.toUTCString(); | ||
var actual = Cookies.set('c', 'v', { expires: 21 }); | ||
assert.ok(actual.indexOf(expected) !== -1, quoted(actual) + ' includes ' + quoted(expected)); | ||
}); | ||
// github.com/carhartl/jquery-cookie/issues/246 | ||
QUnit.test('expires option as fraction of a day', function (assert) { | ||
assert.expect(1); | ||
var now = new Date().getTime(); | ||
var stringifiedDate = Cookies.set('c', 'v', { expires: 0.5 }).split('; ')[1].split('=')[1]; | ||
var expires = Date.parse(stringifiedDate); | ||
var findValueForAttributeName = function (createdCookie, attributeName) { | ||
var pairs = createdCookie.split('; '); | ||
var foundAttributeValue; | ||
pairs.forEach(function (pair) { | ||
if (pair.split('=')[0] === attributeName) { | ||
foundAttributeValue = pair.split('=')[1]; | ||
} | ||
}); | ||
return foundAttributeValue; | ||
}; | ||
var now = new Date(); | ||
var stringifiedDate = findValueForAttributeName(Cookies.set('c', 'v', { expires: 0.5 }), 'expires'); | ||
var expires = new Date(stringifiedDate); | ||
// When we were using Date.setDate() fractions have been ignored | ||
// and expires resulted in the current date. Allow 1000 milliseconds | ||
// difference for execution time. | ||
assert.ok(expires > now + 1000, 'should write expires attribute with the correct date'); | ||
// difference for execution time because new Date() can be different, | ||
// even when it's run synchronously. | ||
// See https://github.com/js-cookie/js-cookie/commit/ecb597b65e4c477baa2b30a2a5a67fdaee9870ea#commitcomment-20146048. | ||
var assertion = expires.getTime() > now.getTime() + 1000; | ||
var message = quoted(expires.getTime()) + ' should be greater than ' + quoted(now.getTime()); | ||
assert.ok(assertion, message); | ||
}); | ||
@@ -206,5 +223,5 @@ | ||
sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); | ||
var expected = 'c=v; expires=' + sevenDaysFromNow.toUTCString(); | ||
var actual = Cookies.set('c', 'v', { expires: sevenDaysFromNow }).substring(0, expected.length); | ||
assert.strictEqual(actual, expected, 'should write the cookie string with expires'); | ||
var expected = 'expires=' + sevenDaysFromNow.toUTCString(); | ||
var actual = Cookies.set('c', 'v', { expires: sevenDaysFromNow }); | ||
assert.ok(actual.indexOf(expected) !== -1, quoted(actual) + ' includes ' + quoted(expected)); | ||
}); | ||
@@ -238,2 +255,9 @@ | ||
QUnit.test('true secure value', function (assert) { | ||
assert.expect(1); | ||
var expected = 'c=v; path=/; secure'; | ||
var actual = Cookies.set('c', 'v', {secure: true}); | ||
assert.strictEqual(actual, expected, 'should add secure attribute'); | ||
}); | ||
// github.com/js-cookie/js-cookie/pull/54 | ||
@@ -247,4 +271,14 @@ QUnit.test('false secure value', function (assert) { | ||
// github.com/js-cookie/js-cookie/issues/276 | ||
QUnit.test('unofficial attribute', function (assert) { | ||
assert.expect(1); | ||
var expected = 'c=v; path=/; unofficial=anything'; | ||
var actual = Cookies.set('c', 'v', { | ||
unofficial: 'anything' | ||
}); | ||
assert.strictEqual(expected, actual, 'should write the cookie string with unofficial attribute'); | ||
}); | ||
QUnit.test('undefined attribute value', function (assert) { | ||
assert.expect(4); | ||
assert.expect(5); | ||
assert.strictEqual(Cookies.set('c', 'v', { | ||
@@ -262,2 +296,5 @@ expires: undefined | ||
}), 'c=v; path=/', 'should not write undefined secure attribute'); | ||
assert.strictEqual(Cookies.set('c', 'v', { | ||
unofficial: undefined | ||
}), 'c=v; path=/', 'should not write undefined unofficial attribute'); | ||
}); | ||
@@ -410,3 +447,3 @@ | ||
assert.expect(2); | ||
Cookies.set('date', new Date(2015, 04, 13, 0, 0, 0, 0)); | ||
Cookies.set('date', new Date(2015, 4, 13, 0, 0, 0, 0)); | ||
assert.strictEqual(Cookies.get('date').indexOf('"'), -1, 'should not quote the stringified Date object'); | ||
@@ -413,0 +450,0 @@ assert.strictEqual(Cookies.getJSON('date').indexOf('"'), -1, 'should not quote the stringified Date object'); |
@@ -122,2 +122,6 @@ // https://github.com/axemclion/grunt-saucelabs#test-result-details-with-qunit | ||
window.quoted = function (input) { | ||
return '"' + input + '"'; | ||
}; | ||
}()); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85768
1559
298