From bd3c9713222bace68d25fe2128c0f8633cad1269 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 23 Feb 2013 19:54:18 +0100 Subject: [PATCH 01/75] Removing test for jQuery --- jquery.cookie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 06d5e21..8463b44 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -6,7 +6,7 @@ * Released under the MIT license */ (function (factory) { - if (typeof define === 'function' && define.amd && define.amd.jQuery) { + if (typeof define === 'function' && define.amd) { // AMD. Register as anonymous module. define(['jquery'], factory); } else { From a09ee1c73969340d5109eb7c0d983cbdbd2f2cc3 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 25 Feb 2013 21:42:04 +0100 Subject: [PATCH 02/75] Set up to build on grunt 0.4.0 --- .gitignore | 3 ++- .jshintrc | 16 ++++++++++++++++ Gruntfile.js | 38 ++++++++++++++++++++++++++++++++++++++ README.md | 4 ++-- grunt.js | 49 ------------------------------------------------- package.json | 26 ++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 .jshintrc create mode 100644 Gruntfile.js delete mode 100644 grunt.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 0baf809..b7dab5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.min.js \ No newline at end of file +node_modules +build \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..b0af059 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,16 @@ +{ + "boss": true, + "browser": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "expr": true, + "evil": true, + "newcap": true, + "noarg": true, + "undef": true, + "globals": { + "define": true, + "jQuery": true + } +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..e61fc3f --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,38 @@ +/*jshint node: true */ + +'use strict'; + +module.exports = function (grunt) { + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + qunit: { + all: ['test/index.html'] + }, + jshint: { + files: [ + 'Gruntfile.js', + 'jquery.cookie.js' + ], + options: { + jshintrc: '.jshintrc' + } + }, + uglify: { + options: { + banner: '/*! <%= pkg.name %> v<%= pkg.version %> | <%= pkg.license %> */\n' + }, + build: { + src: 'jquery.cookie.js', + dest: 'build/jquery.cookie-<%= pkg.version %>.min.js' + } + } + }); + + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-qunit'); + + grunt.registerTask('default', ['jshint', 'qunit']); + grunt.registerTask('ci', ['default']); +}; diff --git a/README.md b/README.md index c745f24..8a92330 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,8 @@ Open in browser: $ open http://0.0.0.0:8124/test/index.html -For quick *non cross-browser* testing use grunt: - +For quick *non cross-browser* testing use grunt, install grunt CLI and project dependencies as outlined in this guide: , then run: + $ grunt ## Development diff --git a/grunt.js b/grunt.js deleted file mode 100644 index 2646eba..0000000 --- a/grunt.js +++ /dev/null @@ -1,49 +0,0 @@ -/*global module */ -module.exports = function (grunt) { - 'use strict'; - - grunt.initConfig({ - pkg: '', - meta: { - banner: '/*! <%= pkg.title %> v<%= pkg.version %> | <%= pkg.licenses[0].type %> */' - }, - qunit: { - files: ['test/index.html'] - }, - lint: { - files: [ - 'grunt.js', - 'jquery.cookie.js' - ] - }, - jshint: { - options: { - boss: true, - browser: true, - curly: true, - eqeqeq: true, - eqnull: true, - expr: true, - evil: true, - newcap: true, - noarg: true, - undef: true - }, - globals: { - define: true, - jQuery: true - } - }, - min: { - dist: { - src: ['', 'jquery.cookie.js'], - dest: 'jquery.cookie-<%= pkg.version %>.min.js' - } - } - }); - - grunt.registerTask('default', 'lint qunit'); - - // Travis CI task. - grunt.registerTask('ci', 'default'); -}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..d2685b8 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "jquery.cookie", + "version": "1.3.1", + "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", + "main": "Gruntfile.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "grunt" + }, + "repository": { + "type": "git", + "url": "git://github.com/carhartl/jquery-cookie.git" + }, + "author": "Klaus Hartl", + "license": "MIT", + "gitHead": "bd3c9713222bace68d25fe2128c0f8633cad1269", + "readmeFilename": "README.md", + "devDependencies": { + "grunt": "~0.4.0", + "grunt-contrib-jshint": "~0.1.0", + "grunt-contrib-uglify": "~0.1.0", + "grunt-contrib-qunit": "~0.1.0" + } +} From 8ebbca5a68f4a2e51a5f79ccdc8f5dbec1b0f9da Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 25 Feb 2013 21:46:19 +0100 Subject: [PATCH 03/75] .travis.yml needs grunt-cli --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a532afb..ab1aa1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,5 @@ language: node_js node_js: - 0.8 before_script: - - npm install grunt + - npm install -g grunt-cli script: grunt ci --verbose \ No newline at end of file From eb39ce5e270198be485f3e4ecd30c89ffbd6be02 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 26 Feb 2013 12:14:07 +0100 Subject: [PATCH 04/75] Fixing writing/removing a cookie with a name that contains characters where encodeURIComponent applies, closes #155. --- jquery.cookie.js | 4 +++- test/tests.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 8463b44..aebaa84 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -49,7 +49,9 @@ value = config.json ? JSON.stringify(value) : String(value); return (document.cookie = [ - encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), + config.raw ? key : encodeURIComponent(key), + '=', + config.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', diff --git a/test/tests.js b/test/tests.js index 343becb..0757ae6 100644 --- a/test/tests.js +++ b/test/tests.js @@ -187,7 +187,8 @@ test('defaults', function () { test('raw = true', function () { expect(1); $.cookie.raw = true; - strictEqual($.cookie('c', ' v').split('=')[1], ' v', 'should not encode'); + strictEqual($.cookie('c[1]', 'v[1]'), 'c[1]=v[1]', 'should not encode'); + $.each($.cookie(), $.removeCookie); }); test('json = true', function () { @@ -242,3 +243,11 @@ test('with options', function() { $.cookie = originalCookie; }); + +test('[] used in name', function () { + expect(1); + $.cookie.raw = true; + document.cookie = 'c[1]=foo'; + $.removeCookie('c[1]'); + strictEqual(document.cookie, '', 'delete the cookie'); +}); From 0b9c6ca456ac8ebe28c59c366065f9d51f10ee42 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 8 Mar 2013 07:46:24 +0100 Subject: [PATCH 05/75] Moving paragraph to the right place [ci skip] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a92330..ac38da1 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,10 @@ Turn on automatic storage of JSON objects passed as the cookie value. Assumes `J ## Cookie Options -### expires - Cookie attributes can be set globally by setting properties of the `$.cookie.defaults` object or individually for each call to `$.cookie()` by passing a plain object to the options argument. Per-call options override the default options. +### expires + expires: 365 Define lifetime of the cookie. Value can be a `Number` which will be interpreted as days from time of creation or a `Date` object. If omitted, the cookie becomes a session cookie. From 047d82fda5eac06b53c89efc94fdd44aec180a67 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 29 Mar 2013 18:07:28 +0100 Subject: [PATCH 06/75] Do not alter options object in $.removeCookie (consider that a reference may have been passed), closes #175 --- jquery.cookie.js | 3 ++- test/tests.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index aebaa84..c4f99af 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -85,7 +85,8 @@ $.removeCookie = function (key, options) { if ($.cookie(key) !== undefined) { - $.cookie(key, '', $.extend(options, { expires: -1 })); + // Must not alter options, thus extending a fresh object... + $.cookie(key, '', $.extend({}, options, { expires: -1 })); return true; } return false; diff --git a/test/tests.js b/test/tests.js index 0757ae6..f83e192 100644 --- a/test/tests.js +++ b/test/tests.js @@ -84,7 +84,7 @@ test('not existing with json = true', function () { test('invalid JSON string with json = true', function () { expect(1); - + if ('JSON' in window) { $.cookie.json = true; @@ -121,7 +121,7 @@ test('call without arguments', function() { foo: 'bar' }, 'should return all cookies'); $.each($.cookie(), $.removeCookie); - + $.cookie.json = true; $.cookie('c', { foo: 'bar' }); deepEqual($.cookie(), { @@ -244,6 +244,15 @@ test('with options', function() { $.cookie = originalCookie; }); +test('passing options reference', function() { + expect(1); + var options = { path: '/' }; + $.cookie('c', 'v', options); + + $.removeCookie('c', options); + deepEqual(options, { path: '/' }, "won't alter options object"); +}); + test('[] used in name', function () { expect(1); $.cookie.raw = true; From 43f15080765e5f1b47a5bb68ed4acd6fabfe9c0e Mon Sep 17 00:00:00 2001 From: Fagner Brack Date: Thu, 27 Jun 2013 13:27:44 -0300 Subject: [PATCH 07/75] Several minor changes to the development process * Add compare_size for better file size diffs, FYI this is the same used by jQuery; * Updating uglify removes reports by default, let's delegate a better diff for compare_size task instead; * Add grunt watch to develop without having to type grunt everytime (need to add to the contributing docs); * Separate cli task from grunt default, so we can enforce minify and compare_size checks for local development; * Add gzip compression for compare_size so we can compare gzipped content too; --- .gitignore | 3 ++- Gruntfile.js | 25 +++++++++++++++++++++---- package.json | 9 ++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b7dab5e..b940627 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -build \ No newline at end of file +build +.sizecache.json \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index e61fc3f..ec6e3c4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -23,8 +23,23 @@ module.exports = function (grunt) { banner: '/*! <%= pkg.name %> v<%= pkg.version %> | <%= pkg.license %> */\n' }, build: { - src: 'jquery.cookie.js', - dest: 'build/jquery.cookie-<%= pkg.version %>.min.js' + files: { + 'build/jquery.cookie-<%= pkg.version %>.min.js': 'jquery.cookie.js' + } + } + }, + watch: { + files: ['jquery.cookie.js', 'test/tests.js'], + tasks: 'default' + }, + compare_size: { + files: [ 'build/jquery.cookie-<%= pkg.version %>.min.js', 'jquery.cookie.js' ], + options: { + compress: { + gz: function( fileContents ) { + return require( 'gzip-js' ).zip( fileContents, {} ).length; + } + } } } }); @@ -32,7 +47,9 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-qunit'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-compare-size'); - grunt.registerTask('default', ['jshint', 'qunit']); - grunt.registerTask('ci', ['default']); + grunt.registerTask('default', ['jshint', 'qunit', 'uglify', 'compare_size']); + grunt.registerTask('ci', ['jshint', 'qunit']); }; diff --git a/package.json b/package.json index d2685b8..258a279 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,11 @@ "readmeFilename": "README.md", "devDependencies": { "grunt": "~0.4.0", - "grunt-contrib-jshint": "~0.1.0", - "grunt-contrib-uglify": "~0.1.0", - "grunt-contrib-qunit": "~0.1.0" + "grunt-contrib-jshint": "~0.4.0", + "grunt-contrib-uglify": "~0.2.0", + "grunt-contrib-qunit": "~0.2.0", + "grunt-contrib-watch": "~0.3.0", + "grunt-compare-size": "~0.4.0", + "gzip-js": "~0.3.0" } } From 006199a6da5e6eaf380ef0c74788bc6b015a8d1e Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 27 Jun 2013 19:05:58 +0200 Subject: [PATCH 08/75] More consistent formatting --- Gruntfile.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ec6e3c4..a7a8e4b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,15 +29,21 @@ module.exports = function (grunt) { } }, watch: { - files: ['jquery.cookie.js', 'test/tests.js'], + files: [ + 'jquery.cookie.js', + 'test/tests.js' + ], tasks: 'default' }, compare_size: { - files: [ 'build/jquery.cookie-<%= pkg.version %>.min.js', 'jquery.cookie.js' ], + files: [ + 'build/jquery.cookie-<%= pkg.version %>.min.js', + 'jquery.cookie.js' + ], options: { compress: { - gz: function( fileContents ) { - return require( 'gzip-js' ).zip( fileContents, {} ).length; + gz: function (fileContents) { + return require('gzip-js').zip(fileContents, {}).length; } } } From 6e301424b28a7e4a123d79fc975f6e477a8623c9 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 27 Jun 2013 19:15:29 +0200 Subject: [PATCH 09/75] Renaming package definition file for latest bower, see #179 --- component.json => bower.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename component.json => bower.json (100%) diff --git a/component.json b/bower.json similarity index 100% rename from component.json rename to bower.json From 60c1126cb6d4edfe078fa75f315a7df196e3e78c Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 27 Jun 2013 19:19:46 +0200 Subject: [PATCH 10/75] Also mentioning bower package definition in changelog, I pushed to fast. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6f464..b886f17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ HEAD (was `null`). Because the return value is still falsy, testing for existence of a cookie like `if ( $.cookie('foo') )` keeps working without change. +- Renamed bower package definition (component.json -> bower.json) for usage + with up-to-date bower. + 1.3.1 ----- - Fixed issue where it was no longer possible to check for an arbitrary cookie, From 9b5607e8302df273ad37fff9e099cc6aedbd1c25 Mon Sep 17 00:00:00 2001 From: Fagner Date: Fri, 5 Jul 2013 22:15:44 -0300 Subject: [PATCH 11/75] Contribution guidelines enhancement Closes gh-181 --- CONTRIBUTING.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 22 ++------------------ 2 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..f174678 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,53 @@ +##Issues + +- Report issues or feature requests on [GitHub Issues](https://github.com/carhartl/jquery-cookie/issues). +- If reporting a bug, please add a [simplified example](http://sscce.org/). + +##Pull requests +- Create a new topic branch for every separate change you make. +- Create a test case if you are fixing a bug or implementing an important feature. +- Make sure the build runs successfully. + +## Development + +###Tools +We use the following tools for development: + +- [Qunit](http://qunitjs.com/) for tests. +- [NodeJS](http://nodejs.org/download/) required to run grunt and the test server only. +- [Grunt](http://gruntjs.com/getting-started) for task management. + +###Getting started +Install [NodeJS](http://nodejs.org/). +Install globally grunt-cli using the following command: + + $ npm install -g grunt-cli + +Browse to the project root directory and install the dev dependencies: + + $ npm install -d + +To execute the build and tests run the following command in the root of the project: + + $ grunt + +You should see a green message in the console: + + Done, without errors. + +###Tests +You can also run the tests in the browser. +Start a test server from the project root: + + $ node test/server.js + +Open the following URL in a browser: + + $ open http://0.0.0.0:8124/test/index.html + +_Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ + +###Automatic build +You can build automatically after a file change using the following command: + + $ grunt watch diff --git a/README.md b/README.md index ac38da1..585ab19 100644 --- a/README.md +++ b/README.md @@ -96,26 +96,8 @@ Define the domain where the cookie is valid. Default: domain of page where the c If true, the cookie transmission requires a secure protocol (https). Default: `false`. -## Tests - -Requires Node. Startup server: - - $ node test/server.js - -Open in browser: - - $ open http://0.0.0.0:8124/test/index.html - -For quick *non cross-browser* testing use grunt, install grunt CLI and project dependencies as outlined in this guide: , then run: - - $ grunt - -## Development - -- Source hosted at [GitHub](https://github.com/carhartl/jquery-cookie) -- Report issues, questions, feature requests on [GitHub Issues](https://github.com/carhartl/jquery-cookie/issues) - -Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change you make. +##Wanna help? +Check out the [Contributing Guidelines](CONTRIBUTING.md) ## Authors From b77bf53a2ee7113c4161abb8ca7c345eae0b11f4 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 17 Aug 2013 20:16:26 +0200 Subject: [PATCH 12/75] Adding files to be ignored by bower, closes #205. --- bower.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 86b1d03..0b29694 100644 --- a/bower.json +++ b/bower.json @@ -6,5 +6,13 @@ ], "dependencies": { "jquery": ">=1.0" - } + }, + "ignore": [ + "test", + ".*", + "*.json", + "*.md", + "*.txt", + "Gruntfile.js" + ] } From bd134a7439ab876117146863e491e72d8d3a1f5a Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 17 Aug 2013 20:18:19 +0200 Subject: [PATCH 13/75] Changing headline --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 585ab19..5dd0b22 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,8 @@ Define the domain where the cookie is valid. Default: domain of page where the c If true, the cookie transmission requires a secure protocol (https). Default: `false`. -##Wanna help? +## Contributing + Check out the [Contributing Guidelines](CONTRIBUTING.md) ## Authors From 43ecd80e4ddf36ac62bf40be35e610b0c19c1538 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 17 Aug 2013 21:46:04 +0200 Subject: [PATCH 14/75] Allow strings to be saved and read while json == true. Also fixes removing such a cookie while json == true. Closes #195. Also see #199. --- jquery.cookie.js | 29 +++++++++++++++-------------- test/tests.js | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index c4f99af..f8f852c 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -17,27 +17,29 @@ var pluses = /\+/g; - function raw(s) { - return s; - } - - function decoded(s) { + function decode(s) { + if (config.raw) { + return s; + } return decodeURIComponent(s.replace(pluses, ' ')); } - function converted(s) { + function decodeAndParse(s) { if (s.indexOf('"') === 0) { - // This is a quoted cookie as according to RFC2068, unescape + // This is a quoted cookie as according to RFC2068, unescape... s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); } + + s = decode(s); + try { return config.json ? JSON.parse(s) : s; - } catch(er) {} + } catch(e) {} } var config = $.cookie = function (key, value, options) { - // write + // Write if (value !== undefined) { options = $.extend({}, config.defaults, options); @@ -59,22 +61,21 @@ ].join('')); } - // read - var decode = config.raw ? raw : decoded; + // Read var cookies = document.cookie.split('; '); var result = key ? undefined : {}; for (var i = 0, l = cookies.length; i < l; i++) { var parts = cookies[i].split('='); var name = decode(parts.shift()); - var cookie = decode(parts.join('=')); + var cookie = parts.join('='); if (key && key === name) { - result = converted(cookie); + result = decodeAndParse(cookie); break; } if (!key) { - result[name] = converted(cookie); + result[name] = decodeAndParse(cookie); } } diff --git a/test/tests.js b/test/tests.js index f83e192..6292319 100644 --- a/test/tests.js +++ b/test/tests.js @@ -82,14 +82,25 @@ test('not existing with json = true', function () { } }); -test('invalid JSON string with json = true', function () { +test('string with json = true', function () { expect(1); - if ('JSON' in window) { $.cookie.json = true; $.cookie('c', 'v'); - strictEqual($.cookie('c'), undefined, "won't throw exception, returns undefined"); + strictEqual($.cookie('c'), 'v', 'should return value'); + } else { + ok(true); + } +}); + +test('invalid JSON string with json = true', function () { + expect(1); + + if ('JSON' in window) { + $.cookie('c', 'v'); + $.cookie.json = true; + strictEqual($.cookie('c'), undefined, "won't throw exception, returns unquoted string"); } else { ok(true); } From 8f68246af8c43aff70e63dde6a4fe868a5f960f4 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sun, 18 Aug 2013 13:22:54 +0200 Subject: [PATCH 15/75] Correcting the test case's description --- test/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.js b/test/tests.js index 6292319..cbcb259 100644 --- a/test/tests.js +++ b/test/tests.js @@ -100,7 +100,7 @@ test('invalid JSON string with json = true', function () { if ('JSON' in window) { $.cookie('c', 'v'); $.cookie.json = true; - strictEqual($.cookie('c'), undefined, "won't throw exception, returns unquoted string"); + strictEqual($.cookie('c'), undefined, "won't throw exception, returns undefined"); } else { ok(true); } From a1e99ef60442a4c7b634d4e60c90b5cd9dc4352d Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 10 Sep 2013 22:42:38 +0200 Subject: [PATCH 16/75] Fix odd result for calling $.cookie() when there are no cookies at all. Closes #212. --- jquery.cookie.js | 8 +++++++- test/tests.js | 18 +++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index f8f852c..ba0b411 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -62,8 +62,14 @@ } // Read - var cookies = document.cookie.split('; '); + var result = key ? undefined : {}; + + // To prevent the for loop in the first place assign an empty array + // in case there are no cookies at all. Also prevents odd result when + // calling $.cookie(). + var cookies = document.cookie ? document.cookie.split('; ') : []; + for (var i = 0, l = cookies.length; i < l; i++) { var parts = cookies[i].split('='); var name = decode(parts.shift()); diff --git a/test/tests.js b/test/tests.js index cbcb259..49287d2 100644 --- a/test/tests.js +++ b/test/tests.js @@ -124,20 +124,20 @@ asyncTest('malformed cookie value in IE (#88, #117)', function() { document.body.appendChild(iframe); }); -test('call without arguments', function() { +test('Call to read all when there are cookies', function() { $.cookie('c', 'v'); $.cookie('foo', 'bar'); - deepEqual($.cookie(), { - c: 'v', - foo: 'bar' - }, 'should return all cookies'); - $.each($.cookie(), $.removeCookie); + deepEqual($.cookie(), { c: 'v', foo: 'bar' }, 'returns object containing all cookies'); +}); + +test('Call to read all when there are no cookies at all', function() { + deepEqual($.cookie(), {}, 'returns empty object'); +}); +test('Call to read all with json: true', function() { $.cookie.json = true; $.cookie('c', { foo: 'bar' }); - deepEqual($.cookie(), { - c: { foo: 'bar' } - }, 'returns all cookies with JSON parsed'); + deepEqual($.cookie(), { c: { foo: 'bar' } }, 'returns JSON parsed cookies'); }); From 81dd6a1596bdcd8e6c4008fcfc6d42825a7c4a2f Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 11 Sep 2013 11:55:43 +0200 Subject: [PATCH 17/75] Handle decoding error gracefully upon reading, return undefined. Closes #215. --- CHANGELOG.md | 3 +++ jquery.cookie.js | 11 ++++++++--- test/tests.js | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b886f17..903a2df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ HEAD - Renamed bower package definition (component.json -> bower.json) for usage with up-to-date bower. +- Badly encoded cookies no longer throw exception upon reading but do return + undefined (similar to how we handle JSON parse errors with json = true). + 1.3.1 ----- - Fixed issue where it was no longer possible to check for an arbitrary cookie, diff --git a/jquery.cookie.js b/jquery.cookie.js index ba0b411..9a25dc2 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -21,7 +21,10 @@ if (config.raw) { return s; } - return decodeURIComponent(s.replace(pluses, ' ')); + try { + // If we can't decode the cookie, ignore it, it's unusable. + return decodeURIComponent(s.replace(pluses, ' ')); + } catch(e) {} } function decodeAndParse(s) { @@ -33,6 +36,7 @@ s = decode(s); try { + // If we can't parse the cookie, ignore it, it's unusable. return config.json ? JSON.parse(s) : s; } catch(e) {} } @@ -80,8 +84,9 @@ break; } - if (!key) { - result[name] = decodeAndParse(cookie); + // Prevent storing a cookie that we couldn't decode. + if (!key && (cookie = decodeAndParse(cookie)) !== undefined) { + result[name] = cookie; } } diff --git a/test/tests.js b/test/tests.js index 49287d2..b45a897 100644 --- a/test/tests.js +++ b/test/tests.js @@ -106,6 +106,13 @@ test('invalid JSON string with json = true', function () { } }); +test('invalid URL encoding', function () { + expect(1); + document.cookie = 'bad=foo%'; + strictEqual($.cookie('bad'), undefined, "won't throw exception, returns undefined"); + document.cookie = 'bad=foo'; // Allow to be deleted... +}); + asyncTest('malformed cookie value in IE (#88, #117)', function() { expect(1); // Sandbox in an iframe so that we can poke around with document.cookie. @@ -140,6 +147,13 @@ test('Call to read all with json: true', function() { deepEqual($.cookie(), { c: { foo: 'bar' } }, 'returns JSON parsed cookies'); }); +test('Call to read all with a badly encoded cookie', function() { + expect(1); + document.cookie = 'bad=foo%'; + document.cookie = 'good=foo'; + deepEqual($.cookie(), { good: 'foo' }, 'returns object containing all decodable cookies'); +}); + module('write', lifecycle); From 939e3fd16bcc539db1530017527465f612b97b8e Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 11 Sep 2013 20:07:13 +0200 Subject: [PATCH 18/75] Consistent formatting. --- test/tests.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/tests.js b/test/tests.js index b45a897..361274d 100644 --- a/test/tests.js +++ b/test/tests.js @@ -113,11 +113,11 @@ test('invalid URL encoding', function () { document.cookie = 'bad=foo'; // Allow to be deleted... }); -asyncTest('malformed cookie value in IE (#88, #117)', function() { +asyncTest('malformed cookie value in IE (#88, #117)', function () { expect(1); // Sandbox in an iframe so that we can poke around with document.cookie. var iframe = $('')[0]; - $(iframe).on('load', function() { + $(iframe).on('load', function () { start(); if (iframe.contentWindow.ok) { strictEqual(iframe.contentWindow.testValue, 'two', 'reads all cookie values, skipping duplicate occurences of "; "'); @@ -131,23 +131,23 @@ asyncTest('malformed cookie value in IE (#88, #117)', function() { document.body.appendChild(iframe); }); -test('Call to read all when there are cookies', function() { +test('Call to read all when there are cookies', function () { $.cookie('c', 'v'); $.cookie('foo', 'bar'); deepEqual($.cookie(), { c: 'v', foo: 'bar' }, 'returns object containing all cookies'); }); -test('Call to read all when there are no cookies at all', function() { +test('Call to read all when there are no cookies at all', function () { deepEqual($.cookie(), {}, 'returns empty object'); }); -test('Call to read all with json: true', function() { +test('Call to read all with json: true', function () { $.cookie.json = true; $.cookie('c', { foo: 'bar' }); deepEqual($.cookie(), { c: { foo: 'bar' } }, 'returns JSON parsed cookies'); }); -test('Call to read all with a badly encoded cookie', function() { +test('Call to read all with a badly encoded cookie', function () { expect(1); document.cookie = 'bad=foo%'; document.cookie = 'good=foo'; @@ -181,7 +181,7 @@ test('number', function () { strictEqual($.cookie('c'), '1234', 'should write value'); }); -test('expires option as days from now', function() { +test('expires option as days from now', function () { expect(1); var sevenDaysFromNow = new Date(); sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); @@ -189,7 +189,7 @@ test('expires option as days from now', function() { 'should write the cookie string with expires'); }); -test('expires option as Date instance', function() { +test('expires option as Date instance', function () { expect(1); var sevenDaysFromNow = new Date(); sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); @@ -231,14 +231,14 @@ test('json = true', function () { module('removeCookie', lifecycle); -test('deletion', function() { +test('deletion', function () { expect(1); $.cookie('c', 'v'); $.removeCookie('c'); strictEqual(document.cookie, '', 'should delete the cookie'); }); -test('return', function() { +test('return', function () { expect(2); strictEqual($.removeCookie('c'), false, "return false if the cookie wasn't found"); @@ -246,12 +246,12 @@ test('return', function() { strictEqual($.removeCookie('c'), true, 'return true if the cookie was found'); }); -test('with options', function() { +test('with options', function () { expect(3); var originalCookie = $.cookie; var callCount = 0; - $.cookie = function() { + $.cookie = function () { callCount++; if (callCount === 1) { // see https://github.com/carhartl/jquery-cookie/issues/99 @@ -269,7 +269,7 @@ test('with options', function() { $.cookie = originalCookie; }); -test('passing options reference', function() { +test('passing options reference', function () { expect(1); var options = { path: '/' }; $.cookie('c', 'v', options); From 43660d48c0a05bbe637acae3ac3468a44451f572 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 5 Oct 2013 14:50:53 +0200 Subject: [PATCH 19/75] On CI, adding a couple of browsers/platforms to run tests on (using Sauce Labs). Closes #192. --- .gitignore | 3 ++- .travis.yml | 10 +++++--- Gruntfile.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++----- README.md | 2 ++ package.json | 4 +++- 5 files changed, 74 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b940627..afea911 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules build -.sizecache.json \ No newline at end of file +.sizecache.json +*.log \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ab1aa1d..3b84117 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ language: node_js node_js: - - 0.8 +- 0.8 before_script: - - npm install -g grunt-cli -script: grunt ci --verbose \ No newline at end of file +- npm install -g grunt-cli +script: grunt ci --verbose +env: + global: + - secure: FjCPTpIs6l6zTvXqH9rPTXqeRCpNa0cmz2Glio8fmOhbdeNbAdQTZGPChe8wTqIQ4wRQUtg4BPZjYx4+ibhj530/QW+736d9UUX5MhixCbm9r6EzRuljlo0wGRsLRa3pHIKyxq18bdilBSYaPrbekpLSyCKM/3wJa34k8LNKdrg= + - secure: dJU6/DdQkuhVNSuaR1OswON7cHjRR7mDv0szIZ1rY/TRNoL6GrDr7XGpeQAtV+6Pqu1RJWb1V0VHoPble6imYqWtiq9LZu8UtU/ImKkZWZxFgMyDDJEli4Lw/+p1UMBNf7jXM3v8t9aOA0eHTwX7IA++paNIdehBOyNI8x3t6Ng= diff --git a/Gruntfile.js b/Gruntfile.js index a7a8e4b..9c30c00 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -47,15 +47,69 @@ module.exports = function (grunt) { } } } + }, + connect: { + server: { + options: { + base: '.', + directory: 'test', + port: 9999 + } + } + }, + 'saucelabs-qunit': { + all: { + options: { + urls: ['http://127.0.0.1:9999/test/index.html'], + tunnelTimeout: 5, + build: process.env.TRAVIS_JOB_ID, + concurrency: 3, + browsers: [ + { + browserName: 'safari', + platform: 'OS X 10.8' + }, + { + browserName: 'firefox', + platform: 'Windows 7' + }, + { + browserName: 'firefox', + platform: 'Windows XP' + }, + { + browserName: 'firefox', + platform: 'Linux' + }, + { + browserName: 'chrome', + platform: 'Windows 7' + }, + { + browserName: 'internet explorer', + platform: 'Windows 8', + version: '10' + }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '9' + } + ], + testname: 'jquery.cookie qunit tests' + } + } } }); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-qunit'); - grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks('grunt-compare-size'); + // Loading dependencies + for (var key in grunt.file.readJSON('package.json').devDependencies) { + if (key !== 'grunt' && key.indexOf('grunt') === 0) { + grunt.loadNpmTasks(key); + } + } grunt.registerTask('default', ['jshint', 'qunit', 'uglify', 'compare_size']); - grunt.registerTask('ci', ['jshint', 'qunit']); + grunt.registerTask('saucelabs', ['connect', 'saucelabs-qunit']); + grunt.registerTask('ci', ['jshint', 'qunit', 'saucelabs']); }; diff --git a/README.md b/README.md index 5dd0b22..a121f55 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) +[![Selenium Test Status](https://saucelabs.com/browser-matrix/carhartl.svg)](https://saucelabs.com/u/carhartl) + A simple, lightweight jQuery plugin for reading, writing and deleting cookies. ## Installation diff --git a/package.json b/package.json index 258a279..761f17a 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,14 @@ "gitHead": "bd3c9713222bace68d25fe2128c0f8633cad1269", "readmeFilename": "README.md", "devDependencies": { - "grunt": "~0.4.0", + "grunt": "~0.4.1", "grunt-contrib-jshint": "~0.4.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-qunit": "~0.2.0", "grunt-contrib-watch": "~0.3.0", "grunt-compare-size": "~0.4.0", + "grunt-saucelabs": "~4.1.1", + "grunt-contrib-connect": "~0.5.0", "gzip-js": "~0.3.0" } } From 64eb7b75ad3165fd842cca68ada02606c5797550 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 20 Aug 2013 17:44:33 +0200 Subject: [PATCH 20/75] Implemented conversion function as optional last argument for reading. Also see #151. Along with it fixed that certain decoding and sanitizing should not happen for a cookie's key. --- CHANGELOG.md | 9 +++++++++ README.md | 21 +++++++++++++++++++++ bower.json | 2 +- cookie.jquery.json | 2 +- jquery.cookie.js | 44 +++++++++++++++++++++++++++----------------- test/tests.js | 18 +++++++++++++++++- 6 files changed, 76 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 903a2df..246232d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,15 @@ HEAD - Badly encoded cookies no longer throw exception upon reading but do return undefined (similar to how we handle JSON parse errors with json = true). +- Added conversion function as optional last argument for reading, + so that values can be changed to a different representation easily on the fly. + Useful for parsing numbers for instance: + + ```javascript + $.cookie('foo', '42'); + $.cookie('foo', Number); // => 42 + ``` + 1.3.1 ----- - Fixed issue where it was no longer possible to check for an arbitrary cookie, diff --git a/README.md b/README.md index a121f55..c3c42dd 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,27 @@ Define the domain where the cookie is valid. Default: domain of page where the c If true, the cookie transmission requires a secure protocol (https). Default: `false`. +## Converters + +Provide a conversion function as optional last argument for reading, in order to change the cookie's value +to a different representation on the fly. + +Example for parsing a value into a number: + +```javascript +$.cookie('foo', '42'); +$.cookie('foo', Number); // => 42 +``` + +Dealing with cookies that have been encoded using `escape` (3rd party cookies): + +```javascript +$.cookie.raw = true; +$.cookie('foo', unescape); +``` + +You can pass an arbitrary conversion function. + ## Contributing Check out the [Contributing Guidelines](CONTRIBUTING.md) diff --git a/bower.json b/bower.json index 0b29694..dd91171 100644 --- a/bower.json +++ b/bower.json @@ -5,7 +5,7 @@ "./jquery.cookie.js" ], "dependencies": { - "jquery": ">=1.0" + "jquery": ">=1.2" }, "ignore": [ "test", diff --git a/cookie.jquery.json b/cookie.jquery.json index 13b1f5e..9267e69 100644 --- a/cookie.jquery.json +++ b/cookie.jquery.json @@ -24,7 +24,7 @@ } ], "dependencies": { - "jquery": ">=1.0" + "jquery": ">=1.2" }, "bugs": "https://github.com/carhartl/jquery-cookie/issues", "homepage": "https://github.com/carhartl/jquery-cookie", diff --git a/jquery.cookie.js b/jquery.cookie.js index 9a25dc2..d1b32c1 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -17,23 +17,31 @@ var pluses = /\+/g; + function encode(s) { + return config.raw ? s : encodeURIComponent(s); + } + function decode(s) { - if (config.raw) { - return s; - } - try { - // If we can't decode the cookie, ignore it, it's unusable. - return decodeURIComponent(s.replace(pluses, ' ')); - } catch(e) {} + return config.raw ? s : decodeURIComponent(s); + } + + function stringifyCookieValue(value) { + return encode(config.json ? JSON.stringify(value) : String(value)); } - function decodeAndParse(s) { + function parseCookieValue(s) { if (s.indexOf('"') === 0) { // This is a quoted cookie as according to RFC2068, unescape... s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); } - s = decode(s); + try { + // Replace server-side written pluses with spaces. + // If we can't decode the cookie, ignore it, it's unusable. + s = decodeURIComponent(s.replace(pluses, ' ')); + } catch(e) { + return; + } try { // If we can't parse the cookie, ignore it, it's unusable. @@ -41,10 +49,15 @@ } catch(e) {} } + function read(s, converter) { + var value = config.raw ? s : parseCookieValue(s); + return $.isFunction(converter) ? converter(value) : value; + } + var config = $.cookie = function (key, value, options) { // Write - if (value !== undefined) { + if (value !== undefined && !$.isFunction(value)) { options = $.extend({}, config.defaults, options); if (typeof options.expires === 'number') { @@ -52,12 +65,8 @@ t.setDate(t.getDate() + days); } - value = config.json ? JSON.stringify(value) : String(value); - return (document.cookie = [ - config.raw ? key : encodeURIComponent(key), - '=', - config.raw ? value : encodeURIComponent(value), + encode(key), '=', stringifyCookieValue(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', @@ -80,12 +89,13 @@ var cookie = parts.join('='); if (key && key === name) { - result = decodeAndParse(cookie); + // If second argument (value) is a function it's a converter... + result = read(cookie, value); break; } // Prevent storing a cookie that we couldn't decode. - if (!key && (cookie = decodeAndParse(cookie)) !== undefined) { + if (!key && (cookie = read(cookie)) !== undefined) { result[name] = cookie; } } diff --git a/test/tests.js b/test/tests.js index 361274d..c5c3171 100644 --- a/test/tests.js +++ b/test/tests.js @@ -65,7 +65,7 @@ test('json = true', function () { if ('JSON' in window) { $.cookie.json = true; $.cookie('c', { foo: 'bar' }); - deepEqual($.cookie('c'), { foo: 'bar'}, 'should parse JSON'); + deepEqual($.cookie('c'), { foo: 'bar' }, 'should parse JSON'); } else { ok(true); } @@ -285,3 +285,19 @@ test('[] used in name', function () { $.removeCookie('c[1]'); strictEqual(document.cookie, '', 'delete the cookie'); }); + + +module('conversion', lifecycle); + +test('read converter', function() { + expect(1); + $.cookie('c', '1'); + strictEqual($.cookie('c', Number), 1, 'converts read value'); +}); + +test('read converter with raw = true', function() { + expect(1); + $.cookie.raw = true; + $.cookie('c', '1'); + strictEqual($.cookie('c', Number), 1, 'does not decode, but converts read value'); +}); From db776243573afd2cb2d6342158e9395d69ef1b23 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 20 Aug 2013 22:06:16 +0200 Subject: [PATCH 21/75] Adding syntax highlighting for remaining code blocks in the README. --- README.md | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c3c42dd..a5ad9f3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,9 @@ A simple, lightweight jQuery plugin for reading, writing and deleting cookies. Include script *after* the jQuery library (unless you are packaging scripts somehow else): - +```html + +``` **Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN. @@ -19,32 +21,44 @@ The plugin can also be loaded as AMD module. Create session cookie: - $.cookie('the_cookie', 'the_value'); +```javascript +$.cookie('the_cookie', 'the_value'); +``` Create expiring cookie, 7 days from then: - $.cookie('the_cookie', 'the_value', { expires: 7 }); +```javascript +$.cookie('the_cookie', 'the_value', { expires: 7 }); +``` Create expiring cookie, valid across entire site: - $.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); +```javascript +$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); +``` Read cookie: - $.cookie('the_cookie'); // => "the_value" - $.cookie('not_existing'); // => undefined +```javascript +$.cookie('the_cookie'); // => "the_value" +$.cookie('not_existing'); // => undefined +``` Read all available cookies: - $.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } +```javascript +$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } +``` Delete cookie: - // Returns true when cookie was found, false when no cookie was found... - $.removeCookie('the_cookie'); +```javascript +// Returns true when cookie was found, false when no cookie was found... +$.removeCookie('the_cookie'); - // Same path as when the cookie was written... - $.removeCookie('the_cookie', { path: '/' }); +// Same path as when the cookie was written... +$.removeCookie('the_cookie', { path: '/' }); +``` *Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.* @@ -54,13 +68,17 @@ Delete cookie: By default the cookie value is encoded/decoded when writing/reading, using `encodeURIComponent`/`decodeURIComponent`. Bypass this by setting raw to true: - $.cookie.raw = true; +```javascript +$.cookie.raw = true; +``` ### json Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`: - $.cookie.json = true; +```javascript +$.cookie.json = true; +``` ## Cookie Options From 3caf209abe30a856789d0ceb464c297dfdbe670e Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 5 Oct 2013 20:24:16 +0200 Subject: [PATCH 22/75] Preparing for 1.4.0 release --- CHANGELOG.md | 3 +++ README.md | 2 +- bower.json | 2 +- cookie.jquery.json | 2 +- jquery.cookie.js | 2 +- package.json | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 246232d..467dd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ HEAD ----- + +1.4.0 +----- - Support for AMD. - Removed deprecated method `$.cookie('name', null)` for deleting a cookie, diff --git a/README.md b/README.md index a5ad9f3..7377611 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ If true, the cookie transmission requires a secure protocol (https). Default: `f ## Converters -Provide a conversion function as optional last argument for reading, in order to change the cookie's value +Provide a conversion function as optional last argument for reading, in order to change the cookie's value to a different representation on the fly. Example for parsing a value into a number: diff --git a/bower.json b/bower.json index dd91171..8a5b5d0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.3.1", + "version": "1.4.0", "main": [ "./jquery.cookie.js" ], diff --git a/cookie.jquery.json b/cookie.jquery.json index 9267e69..522d5e1 100644 --- a/cookie.jquery.json +++ b/cookie.jquery.json @@ -1,6 +1,6 @@ { "name": "cookie", - "version": "1.3.1", + "version": "1.4.0", "title": "jQuery Cookie", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "author": { diff --git a/jquery.cookie.js b/jquery.cookie.js index d1b32c1..9271900 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -1,5 +1,5 @@ /*! - * jQuery Cookie Plugin v1.3.1 + * jQuery Cookie Plugin v1.4.0 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Klaus Hartl diff --git a/package.json b/package.json index 761f17a..3942d32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.3.1", + "version": "1.4.0", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "main": "Gruntfile.js", "directories": { From 0ae9f7eec0f56c677c826094eb126060a50b93b6 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 16 Oct 2013 12:17:58 +0200 Subject: [PATCH 23/75] Fix return value for $.removeCookie() in case cookie deletion failed for whatever reason. Closes #224. --- jquery.cookie.js | 11 +++++----- test/tests.js | 54 ++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 9271900..72d3cd2 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -106,12 +106,13 @@ config.defaults = {}; $.removeCookie = function (key, options) { - if ($.cookie(key) !== undefined) { - // Must not alter options, thus extending a fresh object... - $.cookie(key, '', $.extend({}, options, { expires: -1 })); - return true; + if ($.cookie(key) === undefined) { + return false; } - return false; + + // Must not alter options, thus extending a fresh object... + $.cookie(key, '', $.extend({}, options, { expires: -1 })); + return !$.cookie(key); }; })); diff --git a/test/tests.js b/test/tests.js index c5c3171..8f75b42 100644 --- a/test/tests.js +++ b/test/tests.js @@ -110,7 +110,9 @@ test('invalid URL encoding', function () { expect(1); document.cookie = 'bad=foo%'; strictEqual($.cookie('bad'), undefined, "won't throw exception, returns undefined"); - document.cookie = 'bad=foo'; // Allow to be deleted... + // Delete manually here because it requires raw === true... + $.cookie.raw = true; + $.removeCookie('bad'); }); asyncTest('malformed cookie value in IE (#88, #117)', function () { @@ -152,6 +154,9 @@ test('Call to read all with a badly encoded cookie', function () { document.cookie = 'bad=foo%'; document.cookie = 'good=foo'; deepEqual($.cookie(), { good: 'foo' }, 'returns object containing all decodable cookies'); + // Delete manually here because it requires raw === true... + $.cookie.raw = true; + $.removeCookie('bad'); }); @@ -213,7 +218,8 @@ test('raw = true', function () { expect(1); $.cookie.raw = true; strictEqual($.cookie('c[1]', 'v[1]'), 'c[1]=v[1]', 'should not encode'); - $.each($.cookie(), $.removeCookie); + // Delete manually here because it requires raw === true... + $.removeCookie('c[1]'); }); test('json = true', function () { @@ -238,42 +244,46 @@ test('deletion', function () { strictEqual(document.cookie, '', 'should delete the cookie'); }); -test('return', function () { - expect(2); - strictEqual($.removeCookie('c'), false, "return false if the cookie wasn't found"); - +test('when sucessfully deleted', function () { + expect(1); $.cookie('c', 'v'); - strictEqual($.removeCookie('c'), true, 'return true if the cookie was found'); + strictEqual($.removeCookie('c'), true, 'returns true'); }); -test('with options', function () { - expect(3); - var originalCookie = $.cookie; - var callCount = 0; +test('when deletion failed', function () { + expect(1); + $.cookie('c', 'v'); + var originalCookie = $.cookie; $.cookie = function () { - callCount++; - if (callCount === 1) { - // see https://github.com/carhartl/jquery-cookie/issues/99 - strictEqual(arguments.length, 1, 'look up cookie instead of accidently writing a new'); - return 'cookie'; // act as if a cookie was found... - } - if (callCount === 2) { - strictEqual(arguments[2].foo, 'bar', 'pass along options when deleting cookie'); + // Stub deletion... + if (arguments.length === 1) { + return originalCookie.apply(null, arguments); } }; - $.removeCookie('c', { foo: 'bar' }); - strictEqual(callCount, 2); + strictEqual($.removeCookie('c'), false, 'returns false'); $.cookie = originalCookie; }); -test('passing options reference', function () { +test('when cookie does not exist', function () { + expect(1); + strictEqual($.removeCookie('c'), false, 'returns false'); +}); + +test('with options', function () { expect(1); var options = { path: '/' }; $.cookie('c', 'v', options); + $.removeCookie('c', options); + strictEqual(document.cookie, '', 'should delete the cookie'); +}); +test('passing options reference', function () { + expect(1); + var options = { path: '/' }; + $.cookie('c', 'v', options); $.removeCookie('c', options); deepEqual(options, { path: '/' }, "won't alter options object"); }); From 3ab35ab43ef4aed1c3d463ce8e0a86c914b0d260 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 24 Oct 2013 23:13:32 +0200 Subject: [PATCH 24/75] Using a single try/catch block instead of two. --- jquery.cookie.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 72d3cd2..6aee051 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -38,13 +38,8 @@ try { // Replace server-side written pluses with spaces. // If we can't decode the cookie, ignore it, it's unusable. - s = decodeURIComponent(s.replace(pluses, ' ')); - } catch(e) { - return; - } - - try { // If we can't parse the cookie, ignore it, it's unusable. + s = decodeURIComponent(s.replace(pluses, ' ')); return config.json ? JSON.parse(s) : s; } catch(e) {} } From 7984c941e06b071eaf3eac9cfbd171decd3b75b2 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 30 Oct 2013 16:20:01 +0100 Subject: [PATCH 25/75] Adding Code Climate badge. Closes #228. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7377611..dfa1586 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) +# jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) [![Selenium Test Status](https://saucelabs.com/browser-matrix/carhartl.svg)](https://saucelabs.com/u/carhartl) From 8947f435c39b209d1ef4c46284702c2e0d03678b Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 30 Oct 2013 16:41:28 +0100 Subject: [PATCH 26/75] Using correctly set up Sauce Labs account (one for open source). Should fix badge not showing up. --- .travis.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b84117..b65fdbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,5 @@ before_script: script: grunt ci --verbose env: global: - - secure: FjCPTpIs6l6zTvXqH9rPTXqeRCpNa0cmz2Glio8fmOhbdeNbAdQTZGPChe8wTqIQ4wRQUtg4BPZjYx4+ibhj530/QW+736d9UUX5MhixCbm9r6EzRuljlo0wGRsLRa3pHIKyxq18bdilBSYaPrbekpLSyCKM/3wJa34k8LNKdrg= - - secure: dJU6/DdQkuhVNSuaR1OswON7cHjRR7mDv0szIZ1rY/TRNoL6GrDr7XGpeQAtV+6Pqu1RJWb1V0VHoPble6imYqWtiq9LZu8UtU/ImKkZWZxFgMyDDJEli4Lw/+p1UMBNf7jXM3v8t9aOA0eHTwX7IA++paNIdehBOyNI8x3t6Ng= + - secure: HRae0kyIDDuhonvMi2SfEl1WJb4K/wX8WmzT9YkxFbmWwLjiOMkmqyuEyi76DbTC1cb9o7WwGVgbP1DhSm6n6m0Lz+PSzpprBN4QZuJc56jcc+tBA6gM81hyUufaTT0yUWz112Bu06kWIAs44w5PtG0FYZR0CuIN8fQvZi8fXCQ= + - secure: c+M5ECIfxDcVrr+ZlqgpGjv8kVM/hxiz3ACMCn4ZkDiaeq4Rw0wWIGZYL6aV5fhsoHgzEQ/XQPca8xKs3Umr7R3b6Vr3AEyFnW+LP67K/1Qbz4Pi3PvhDH/h4rvK7fOoTqTDCVVDEH3v4pefsz2VaKemG4iBKxrcof5aR4Rjopk= diff --git a/README.md b/README.md index dfa1586..1c1f068 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) -[![Selenium Test Status](https://saucelabs.com/browser-matrix/carhartl.svg)](https://saucelabs.com/u/carhartl) +[![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) A simple, lightweight jQuery plugin for reading, writing and deleting cookies. From ac265dcb3bd0d18252396a0ce6db5c4a4c420069 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 31 Oct 2013 09:09:15 +0100 Subject: [PATCH 27/75] Moving build status matrix below description. [ci skip] --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c1f068..e409147 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) -[![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) - A simple, lightweight jQuery plugin for reading, writing and deleting cookies. +## Build Status Matrix + +[![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) + ## Installation Include script *after* the jQuery library (unless you are packaging scripts somehow else): From 580416a8b08e33d819a92fca7f4caa8d9ca6527c Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 26 Nov 2013 16:51:36 +0200 Subject: [PATCH 28/75] add jspm package.json config --- package.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/package.json b/package.json index 3942d32..2553b83 100644 --- a/package.json +++ b/package.json @@ -27,5 +27,12 @@ "grunt-saucelabs": "~4.1.1", "grunt-contrib-connect": "~0.5.0", "gzip-js": "~0.3.0" + }, + "jspm": { + "main": "jquery.cookie", + "files": ["jquery.cookie.js"], + "buildConfig": { + "uglify": true + } } } From ecb597b65e4c477baa2b30a2a5a67fdaee9870ea Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 29 Nov 2013 22:54:53 +0100 Subject: [PATCH 29/75] Allow fractions of a day for expires option. Closes #246. --- jquery.cookie.js | 3 ++- test/tests.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 6aee051..6412847 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -52,12 +52,13 @@ var config = $.cookie = function (key, value, options) { // Write + if (value !== undefined && !$.isFunction(value)) { options = $.extend({}, config.defaults, options); if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new Date(); - t.setDate(t.getDate() + days); + t.setTime(+t + days * 864e+5); } return (document.cookie = [ diff --git a/test/tests.js b/test/tests.js index 8f75b42..f1c357a 100644 --- a/test/tests.js +++ b/test/tests.js @@ -194,6 +194,18 @@ test('expires option as days from now', function () { 'should write the cookie string with expires'); }); +test('expires option as fraction of a day', function () { + expect(1); + + now = new Date().getTime(); + expires = Date.parse($.cookie('c', 'v', { expires: 0.5 })); + + // When we were using Date.setDate() fractions have been ignored + // and expires resulted in the current date. Allow 1000 milliseconds + // difference for execution time. + ok(expires > now + 1000, 'should write expires attribute with the correct date'); +}); + test('expires option as Date instance', function () { expect(1); var sevenDaysFromNow = new Date(); From fbb0117ff06f7d7410c4243af8906e64d3ad27de Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 30 Nov 2013 14:06:17 +0100 Subject: [PATCH 30/75] Date.parse works a bit different in Firefox and IE and Webkit. Also fixing the creation of global variables in the test. --- test/tests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests.js b/test/tests.js index f1c357a..bd32552 100644 --- a/test/tests.js +++ b/test/tests.js @@ -197,8 +197,8 @@ test('expires option as days from now', function () { test('expires option as fraction of a day', function () { expect(1); - now = new Date().getTime(); - expires = Date.parse($.cookie('c', 'v', { expires: 0.5 })); + var now = new Date().getTime(); + var expires = Date.parse($.cookie('c', 'v', { expires: 0.5 }).replace(/.+expires=/, '')); // When we were using Date.setDate() fractions have been ignored // and expires resulted in the current date. Allow 1000 milliseconds From d24eb23c3f045fe96e9e2993529a91478a97fca8 Mon Sep 17 00:00:00 2001 From: "Bruno Winck, Kneaver" Date: Fri, 27 Dec 2013 15:21:37 +0530 Subject: [PATCH 31/75] Add component.json to support component.io --- component.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 component.json diff --git a/component.json b/component.json new file mode 100644 index 0000000..5e6ae45 --- /dev/null +++ b/component.json @@ -0,0 +1,14 @@ +{ + "name": "jquery.cookie", + "repo": "carhartl/jquery-cookie", + "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies", + "version": "1.4.0", + "keywords": [], + "dependencies": {}, + "development": {}, + "license": "MIT", + "main": "jquery.cookie.js", + "scripts": [ + "jquery.cookie.js" + ] +} \ No newline at end of file From 3646a0de3e271641a3e232d39e29e71bdab16850 Mon Sep 17 00:00:00 2001 From: Colin Rymer Date: Tue, 28 Jan 2014 11:02:28 -0500 Subject: [PATCH 32/75] add jamjs support --- package.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/package.json b/package.json index 2553b83..721ca67 100644 --- a/package.json +++ b/package.json @@ -34,5 +34,14 @@ "buildConfig": { "uglify": true } + }, + "jam": { + "dependencies": { + "jquery": ">=1.2" + }, + "main": "jquery.cookie.js", + "include": [ + "jquery.cookie.js" + ] } } From 433a10696e71f1584662cae507c404f4bfbb9526 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 28 Jan 2014 21:03:09 +0100 Subject: [PATCH 33/75] Adding note about the documentation in master vs latest release --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e409147..6def3e1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ A simple, lightweight jQuery plugin for reading, writing and deleting cookies. +**If you're viewing this at https://github.com/carhartl/jquery-cookie, you're reading the documentation for the master branch. +[View documentation for the latest release (1.4.0).](https://github.com/carhartl/jquery-cookie/tree/v1.4.0)** + ## Build Status Matrix [![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) From 92c3fd0ad5cfa45ff03914969912fad4c4a9861a Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Mon, 10 Feb 2014 15:48:51 -0700 Subject: [PATCH 34/75] Fix package.json main property This allows tools like volo to know which file to include in a dependent's lib directory. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2553b83..07395f5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery.cookie", "version": "1.4.0", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", - "main": "Gruntfile.js", + "main": "jquery.cookie.js", "directories": { "test": "test" }, From 5421819450666bada6d1aed655cfaf4e85a4f88b Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Mon, 10 Feb 2014 15:51:36 -0700 Subject: [PATCH 35/75] Download hint for volo --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 2553b83..9324fee 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ "grunt-contrib-connect": "~0.5.0", "gzip-js": "~0.3.0" }, + "volo": { + "url": "https://raw.github.com/carhartl/jquery-cookie/v{version}/jquery.cookie.js" + }, "jspm": { "main": "jquery.cookie", "files": ["jquery.cookie.js"], From 6e175cd71e0d4cf8b64739b3128ddef5a33c938a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gasto=CC=81n=20Omar=20Sa=CC=81nchez=20Rui=CC=81z?= Date: Tue, 11 Feb 2014 21:36:39 -0600 Subject: [PATCH 36/75] Add CommonJS support --- .jshintrc | 3 ++- README.md | 2 +- jquery.cookie.js | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.jshintrc b/.jshintrc index b0af059..a37f48c 100644 --- a/.jshintrc +++ b/.jshintrc @@ -11,6 +11,7 @@ "undef": true, "globals": { "define": true, - "jQuery": true + "jQuery": true, + "require": true } } diff --git a/README.md b/README.md index 6def3e1..536b5a0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Include script *after* the jQuery library (unless you are packaging scripts some **Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN. -The plugin can also be loaded as AMD module. +The plugin can also be loaded as AMD or CommonJS module. ## Usage diff --git a/jquery.cookie.js b/jquery.cookie.js index 6412847..2f84144 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -9,6 +9,9 @@ if (typeof define === 'function' && define.amd) { // AMD. Register as anonymous module. define(['jquery'], factory); + } else if (typeof exports === 'object') { + // CommonJS + factory(require('jquery')); } else { // Browser globals. factory(jQuery); From 187c874c6727f4c9518e6565e1b742192de80bb5 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 28 Feb 2014 20:08:17 +0100 Subject: [PATCH 37/75] Write comments in a consistent manner --- jquery.cookie.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 2f84144..211da5c 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -7,13 +7,13 @@ */ (function (factory) { if (typeof define === 'function' && define.amd) { - // AMD. Register as anonymous module. + // AMD define(['jquery'], factory); } else if (typeof exports === 'object') { // CommonJS factory(require('jquery')); } else { - // Browser globals. + // Browser globals factory(jQuery); } }(function ($) { From 5b12a4e11dd167d6227cb866ee6e88134cdae813 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 28 Feb 2014 20:34:35 +0100 Subject: [PATCH 38/75] Adding missing newline at the end --- component.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component.json b/component.json index 5e6ae45..6b7122a 100644 --- a/component.json +++ b/component.json @@ -11,4 +11,4 @@ "scripts": [ "jquery.cookie.js" ] -} \ No newline at end of file +} From 8f641ded8a1f6b7697161e258592c9d388d15485 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 4 Mar 2014 09:55:57 +0100 Subject: [PATCH 39/75] Updating changelog, preparing for next release --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 467dd42..80511c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ HEAD ----- +- Added support for CommonJS. + +- Added support for package managers: Jam (http://jamjs.org), volo (http://volojs.org), Component (http://component.io), jspm (http://jspm.io). + +- The expires option now interpretes fractions of numbers (e.g. days) correctly. + 1.4.0 ----- - Support for AMD. From 9481ec9eb649e10cd8650d58c0170a36b2da10e7 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 4 Mar 2014 09:58:05 +0100 Subject: [PATCH 40/75] Removing newline --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80511c2..e72e6d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ HEAD ----- - - Added support for CommonJS. - Added support for package managers: Jam (http://jamjs.org), volo (http://volojs.org), Component (http://component.io), jspm (http://jspm.io). From 38b998b9780e52da3952ab57572c36f46280a79a Mon Sep 17 00:00:00 2001 From: Nicholas Van de walle Date: Fri, 14 Mar 2014 09:00:09 -0700 Subject: [PATCH 41/75] Update MIT-LICENSE.txt Updated your license to the current year. --- MIT-LICENSE.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt index 8ae647b..7a631e8 100644 --- a/MIT-LICENSE.txt +++ b/MIT-LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2013 Klaus Hartl +Copyright 2014 Klaus Hartl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 7f88a4e631aba8a8c688fd8999ce6b9bcfd50718 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sun, 27 Apr 2014 22:07:15 +0200 Subject: [PATCH 42/75] Preparing for 1.4.1 release --- CHANGELOG.md | 3 +++ README.md | 2 +- bower.json | 2 +- component.json | 2 +- cookie.jquery.json | 2 +- jquery.cookie.js | 2 +- package.json | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e72e6d2..59d868f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ HEAD ----- + +1.4.1 +----- - Added support for CommonJS. - Added support for package managers: Jam (http://jamjs.org), volo (http://volojs.org), Component (http://component.io), jspm (http://jspm.io). diff --git a/README.md b/README.md index 536b5a0..f9a7494 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A simple, lightweight jQuery plugin for reading, writing and deleting cookies. **If you're viewing this at https://github.com/carhartl/jquery-cookie, you're reading the documentation for the master branch. -[View documentation for the latest release (1.4.0).](https://github.com/carhartl/jquery-cookie/tree/v1.4.0)** +[View documentation for the latest release (1.4.1).](https://github.com/carhartl/jquery-cookie/tree/v1.4.1)** ## Build Status Matrix diff --git a/bower.json b/bower.json index 8a5b5d0..2d8c25b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.4.0", + "version": "1.4.1", "main": [ "./jquery.cookie.js" ], diff --git a/component.json b/component.json index 6b7122a..58f79d6 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "jquery.cookie", "repo": "carhartl/jquery-cookie", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies", - "version": "1.4.0", + "version": "1.4.1", "keywords": [], "dependencies": {}, "development": {}, diff --git a/cookie.jquery.json b/cookie.jquery.json index 522d5e1..69d5748 100644 --- a/cookie.jquery.json +++ b/cookie.jquery.json @@ -1,6 +1,6 @@ { "name": "cookie", - "version": "1.4.0", + "version": "1.4.1", "title": "jQuery Cookie", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "author": { diff --git a/jquery.cookie.js b/jquery.cookie.js index 211da5c..c7f3a59 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -1,5 +1,5 @@ /*! - * jQuery Cookie Plugin v1.4.0 + * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Klaus Hartl diff --git a/package.json b/package.json index e5493d1..d52070a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.4.0", + "version": "1.4.1", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "main": "jquery.cookie.js", "directories": { From 120dc4cd1bbac59a1b6ce4e80a158b54cda68b81 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 28 Apr 2014 21:59:21 +0200 Subject: [PATCH 43/75] Updating Sauce Labs browsers to test in CI, closes #288 --- Gruntfile.js | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9c30c00..acd3c77 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -65,35 +65,80 @@ module.exports = function (grunt) { build: process.env.TRAVIS_JOB_ID, concurrency: 3, browsers: [ + // iOS { - browserName: 'safari', - platform: 'OS X 10.8' + browserName: 'iphone', + platform: 'OS X 10.9', + version: '7.1' }, { - browserName: 'firefox', - platform: 'Windows 7' + browserName: 'ipad', + platform: 'OS X 10.9', + version: '7.1' }, + // Android { - browserName: 'firefox', - platform: 'Windows XP' + browserName: 'android', + platform: 'Linux', + version: '4.3' }, + // OS X { - browserName: 'firefox', - platform: 'Linux' + browserName: 'safari', + platform: 'OS X 10.9', + version: '7' }, { - browserName: 'chrome', - platform: 'Windows 7' + browserName: 'safari', + platform: 'OS X 10.8', + version: '6' + }, + // Windows + { + browserName: 'internet explorer', + platform: 'Windows 8.1', + version: '11' }, { browserName: 'internet explorer', platform: 'Windows 8', version: '10' }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '11' + }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '10' + }, { browserName: 'internet explorer', platform: 'Windows 7', version: '9' + }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '8' + }, + { + browserName: 'firefox', + platform: 'Windows 7', + version: '28' + }, + { + browserName: 'chrome', + platform: 'Windows 7', + version: '34' + }, + // Linux + { + browserName: 'firefox', + platform: 'Linux', + version: '28' } ], testname: 'jquery.cookie qunit tests' From 288af0659a8371fa1128133f1205eac3afb4633a Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 6 May 2014 09:54:31 +0200 Subject: [PATCH 44/75] Updating to use latest Firefox for Sauce Labs CI --- Gruntfile.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index acd3c77..cb0df23 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -93,6 +93,11 @@ module.exports = function (grunt) { platform: 'OS X 10.8', version: '6' }, + { + browserName: 'firefox', + platform: 'OS X 10.9', + version: '28' + }, // Windows { browserName: 'internet explorer', @@ -127,7 +132,7 @@ module.exports = function (grunt) { { browserName: 'firefox', platform: 'Windows 7', - version: '28' + version: '29' }, { browserName: 'chrome', @@ -138,7 +143,7 @@ module.exports = function (grunt) { { browserName: 'firefox', platform: 'Linux', - version: '28' + version: '29' } ], testname: 'jquery.cookie qunit tests' From e2a881c9694a39b57cb7eff8a4f64ebd6a144456 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 6 May 2014 10:03:30 +0200 Subject: [PATCH 45/75] Update jQuery used in the tests --- test/index.html | 2 +- test/malformed_cookie.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.html b/test/index.html index 1a6016b..2c0aec1 100644 --- a/test/index.html +++ b/test/index.html @@ -4,7 +4,7 @@ jquery.cookie Test Suite - + diff --git a/test/malformed_cookie.html b/test/malformed_cookie.html index b4a3f78..3aab83f 100644 --- a/test/malformed_cookie.html +++ b/test/malformed_cookie.html @@ -2,7 +2,7 @@ - + - + From e9fe5559e4b69aedf6a916a3e27e2a8cfda6f079 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 21:51:57 +0200 Subject: [PATCH 47/75] Use `grunt connect:server:keepalive` to start a server, removing the one in test. Closes #287. --- CONTRIBUTING.md | 6 +++--- test/server.js | 24 ------------------------ 2 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 test/server.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f174678..50ef6d5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,7 @@ We use the following tools for development: - [Qunit](http://qunitjs.com/) for tests. -- [NodeJS](http://nodejs.org/download/) required to run grunt and the test server only. +- [NodeJS](http://nodejs.org/download/) required to run grunt. - [Grunt](http://gruntjs.com/getting-started) for task management. ###Getting started @@ -39,11 +39,11 @@ You should see a green message in the console: You can also run the tests in the browser. Start a test server from the project root: - $ node test/server.js + $ grunt connect:server:keepalive Open the following URL in a browser: - $ open http://0.0.0.0:8124/test/index.html + $ open http://127.0.0.1:9999/test/index.html _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/test/server.js b/test/server.js deleted file mode 100644 index 8d2e712..0000000 --- a/test/server.js +++ /dev/null @@ -1,24 +0,0 @@ -var http = require('http'); -var url = require('url'); -var path = require('path'); -var fs = require('fs'); - -http.createServer(function(request, response) { - var uri = url.parse(request.url).pathname; - var filename = path.join(process.cwd(), uri); - - fs.readFile(filename, 'binary', function(err, file) { - if (err) { - response.writeHead(500, { 'Content-Type': 'text/plain' }); - response.write(err + '\n'); - response.end(); - return; - } - - response.writeHead(200, filename.match(/\.js$/) ? { 'Content-Type': 'text/javascript' } : {}); - response.write(file, 'utf-8'); - response.end(); - }); -}).listen(8124, '0.0.0.0'); - -console.log('Test suite at http://0.0.0.0:8124/test/index.html'); From c5ad0163f0259553b6933f3ef72f80c80db5fa9c Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 22:07:54 +0200 Subject: [PATCH 48/75] Fixing indentation in the yaml --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b65fdbd..d479758 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: node_js node_js: -- 0.8 + - 0.8 before_script: -- npm install -g grunt-cli + - npm install -g grunt-cli script: grunt ci --verbose env: global: - - secure: HRae0kyIDDuhonvMi2SfEl1WJb4K/wX8WmzT9YkxFbmWwLjiOMkmqyuEyi76DbTC1cb9o7WwGVgbP1DhSm6n6m0Lz+PSzpprBN4QZuJc56jcc+tBA6gM81hyUufaTT0yUWz112Bu06kWIAs44w5PtG0FYZR0CuIN8fQvZi8fXCQ= - - secure: c+M5ECIfxDcVrr+ZlqgpGjv8kVM/hxiz3ACMCn4ZkDiaeq4Rw0wWIGZYL6aV5fhsoHgzEQ/XQPca8xKs3Umr7R3b6Vr3AEyFnW+LP67K/1Qbz4Pi3PvhDH/h4rvK7fOoTqTDCVVDEH3v4pefsz2VaKemG4iBKxrcof5aR4Rjopk= + - secure: HRae0kyIDDuhonvMi2SfEl1WJb4K/wX8WmzT9YkxFbmWwLjiOMkmqyuEyi76DbTC1cb9o7WwGVgbP1DhSm6n6m0Lz+PSzpprBN4QZuJc56jcc+tBA6gM81hyUufaTT0yUWz112Bu06kWIAs44w5PtG0FYZR0CuIN8fQvZi8fXCQ= + - secure: c+M5ECIfxDcVrr+ZlqgpGjv8kVM/hxiz3ACMCn4ZkDiaeq4Rw0wWIGZYL6aV5fhsoHgzEQ/XQPca8xKs3Umr7R3b6Vr3AEyFnW+LP67K/1Qbz4Pi3PvhDH/h4rvK7fOoTqTDCVVDEH3v4pefsz2VaKemG4iBKxrcof5aR4Rjopk= From da0e4ac0904eab8bc609c10620e19bb1abc0aa91 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 22:08:42 +0200 Subject: [PATCH 49/75] Updating node version to use in CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d479758..bfd8ca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 0.8 + - 0.10 before_script: - npm install -g grunt-cli script: grunt ci --verbose From 1f14c0053ea8f1a77144871ffdc2334a1ea5bbae Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 23:22:54 +0200 Subject: [PATCH 50/75] Adding a connect:tests task, to automatically open tests in the default browser. Updating grunt-contrib-connect. --- CONTRIBUTING.md | 6 ++---- Gruntfile.js | 17 ++++++++++++++--- package.json | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 50ef6d5..7bcfcfa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,11 +39,9 @@ You should see a green message in the console: You can also run the tests in the browser. Start a test server from the project root: - $ grunt connect:server:keepalive + $ grunt connect:tests -Open the following URL in a browser: - - $ open http://127.0.0.1:9999/test/index.html +This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser. _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/Gruntfile.js b/Gruntfile.js index cb0df23..bf0e538 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -49,12 +49,23 @@ module.exports = function (grunt) { } }, connect: { - server: { + all: { options: { base: '.', - directory: 'test', + directory: 'test' + } + }, + saucelabs: { + options: { port: 9999 } + }, + tests: { + options: { + open: 'http://127.0.0.1:9998/test/index.html', + keepalive: true, + port: 9998 + } } }, 'saucelabs-qunit': { @@ -160,6 +171,6 @@ module.exports = function (grunt) { } grunt.registerTask('default', ['jshint', 'qunit', 'uglify', 'compare_size']); - grunt.registerTask('saucelabs', ['connect', 'saucelabs-qunit']); + grunt.registerTask('saucelabs', ['connect:saucelabs', 'saucelabs-qunit']); grunt.registerTask('ci', ['jshint', 'qunit', 'saucelabs']); }; diff --git a/package.json b/package.json index d52070a..b56857e 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "grunt-contrib-watch": "~0.3.0", "grunt-compare-size": "~0.4.0", "grunt-saucelabs": "~4.1.1", - "grunt-contrib-connect": "~0.5.0", + "grunt-contrib-connect": "~0.7.1", "gzip-js": "~0.3.0" }, "volo": { From f2b6b252b01cb24a5619744730022d860d3215e1 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 23:49:19 +0200 Subject: [PATCH 51/75] Enable livereload for test suite when opened in the browser via grunt task --- CONTRIBUTING.md | 2 +- Gruntfile.js | 6 +++++- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7bcfcfa..7ad0146 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ Start a test server from the project root: $ grunt connect:tests -This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser. +This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser, with livereload enabled. _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/Gruntfile.js b/Gruntfile.js index bf0e538..9751c56 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,6 +29,9 @@ module.exports = function (grunt) { } }, watch: { + options: { + livereload: true + }, files: [ 'jquery.cookie.js', 'test/tests.js' @@ -62,9 +65,10 @@ module.exports = function (grunt) { }, tests: { options: { + port: 9998, open: 'http://127.0.0.1:9998/test/index.html', keepalive: true, - port: 9998 + livereload: true } } }, diff --git a/package.json b/package.json index b56857e..e865106 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "grunt-contrib-jshint": "~0.4.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-qunit": "~0.2.0", - "grunt-contrib-watch": "~0.3.0", + "grunt-contrib-watch": "~0.6.1", "grunt-compare-size": "~0.4.0", "grunt-saucelabs": "~4.1.1", "grunt-contrib-connect": "~0.7.1", From e3a19c3e6dbd7c3ebd4a350bee7d8de1dd4dafed Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 29 May 2014 00:08:05 +0200 Subject: [PATCH 52/75] Improving Readme --- README.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f9a7494..0a6f08e 100644 --- a/README.md +++ b/README.md @@ -27,42 +27,47 @@ The plugin can also be loaded as AMD or CommonJS module. Create session cookie: ```javascript -$.cookie('the_cookie', 'the_value'); +$.cookie('name', 'value'); ``` Create expiring cookie, 7 days from then: ```javascript -$.cookie('the_cookie', 'the_value', { expires: 7 }); +$.cookie('name', 'value', { expires: 7 }); ``` Create expiring cookie, valid across entire site: ```javascript -$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); +$.cookie('name', 'value', { expires: 7, path: '/' }); ``` Read cookie: ```javascript -$.cookie('the_cookie'); // => "the_value" -$.cookie('not_existing'); // => undefined +$.cookie('name'); // => "value" +$.cookie('nothing'); // => undefined ``` Read all available cookies: ```javascript -$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } +$.cookie(); // => { "name": "value" } ``` Delete cookie: ```javascript -// Returns true when cookie was found, false when no cookie was found... -$.removeCookie('the_cookie'); - -// Same path as when the cookie was written... -$.removeCookie('the_cookie', { path: '/' }); +// Returns true when cookie was successfully deleted, otherwise false +$.removeCookie('name'); // => true +$.removeCookie('nothing'); // => false + +// Need to use the same attributes (path, domain) as what the cookie was written with +$.cookie('name', 'value', { path: '/' }); +// This won't work! +$.removeCookie('name'); // => false +// This will work! +$.removeCookie('name', { path: '/' }); // => true ``` *Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.* From f81174035cc52298efb5a31afc86026516ad29ca Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 21:45:19 +0200 Subject: [PATCH 53/75] Updating grunt-saucelabs package. Required a workaround for exposing test results to the Sauce Labs API. --- Gruntfile.js | 5 +---- package.json | 2 +- test/tests.js | 8 ++++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9751c56..5b44abb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,9 +76,7 @@ module.exports = function (grunt) { all: { options: { urls: ['http://127.0.0.1:9999/test/index.html'], - tunnelTimeout: 5, build: process.env.TRAVIS_JOB_ID, - concurrency: 3, browsers: [ // iOS { @@ -160,8 +158,7 @@ module.exports = function (grunt) { platform: 'Linux', version: '29' } - ], - testname: 'jquery.cookie qunit tests' + ] } } } diff --git a/package.json b/package.json index e865106..46c89b5 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "grunt-contrib-qunit": "~0.2.0", "grunt-contrib-watch": "~0.6.1", "grunt-compare-size": "~0.4.0", - "grunt-saucelabs": "~4.1.1", + "grunt-saucelabs": "~7.0.0", "grunt-contrib-connect": "~0.7.1", "gzip-js": "~0.3.0" }, diff --git a/test/tests.js b/test/tests.js index bd32552..008f121 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,3 +1,11 @@ +// Required for exposing test results to the Sauce Labs API. +// Can be removed when the following issue is fixed: +// https://github.com/axemclion/grunt-saucelabs/issues/84 +QUnit.done(function (details) { + window.global_test_results = details; +}); + + var lifecycle = { teardown: function () { $.cookie.defaults = {}; From 18fc9a124d377aaea6f90daa29084ad16571ab9b Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:07:01 +0200 Subject: [PATCH 54/75] Also ignore logs of the form log.1 etc. (created by Sauce Labs) --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index afea911..15812b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules build .sizecache.json -*.log \ No newline at end of file +*.log* From 1a98e9ce0c330d420b70887a02805bb67d0945d8 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:13:00 +0200 Subject: [PATCH 55/75] Removing obsolete options for the connect task --- Gruntfile.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 5b44abb..2f0906e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -52,12 +52,6 @@ module.exports = function (grunt) { } }, connect: { - all: { - options: { - base: '.', - directory: 'test' - } - }, saucelabs: { options: { port: 9999 From 1c710ecf3f3e32c47c8ccf632ac3a8156a4c43f9 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:35:42 +0200 Subject: [PATCH 56/75] Updating grunt-contrib-jshint package. --- Gruntfile.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 2f0906e..3bc12c6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -15,7 +15,7 @@ module.exports = function (grunt) { 'jquery.cookie.js' ], options: { - jshintrc: '.jshintrc' + jshintrc: true } }, uglify: { diff --git a/package.json b/package.json index 46c89b5..b15b7ad 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "readmeFilename": "README.md", "devDependencies": { "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.4.0", + "grunt-contrib-jshint": "~0.10.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-qunit": "~0.2.0", "grunt-contrib-watch": "~0.6.1", From a5aa50fb369bb1b21ba9f928a7da525c6d204061 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:57:13 +0200 Subject: [PATCH 57/75] Minimal html for QUnit --- test/index.html | 11 ++++------- test/malformed_cookie.html | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/index.html b/test/index.html index 814f60c..841310b 100644 --- a/test/index.html +++ b/test/index.html @@ -1,19 +1,16 @@ - + jquery.cookie Test Suite - + -

jquery.cookie Test Suite

-

-
-

-
    +
    +
    diff --git a/test/malformed_cookie.html b/test/malformed_cookie.html index 3aab83f..17e8db8 100644 --- a/test/malformed_cookie.html +++ b/test/malformed_cookie.html @@ -1,4 +1,4 @@ - + From 3f1f88b72503e7f993508b2caf37b1d4c0d39f4b Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 31 May 2014 00:00:56 +0200 Subject: [PATCH 58/75] Also lint tests. For this, moving jshint options into Gruntfile... Updated options as well. --- .jshintrc | 17 ----------------- Gruntfile.js | 54 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 25 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index a37f48c..0000000 --- a/.jshintrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "boss": true, - "browser": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "expr": true, - "evil": true, - "newcap": true, - "noarg": true, - "undef": true, - "globals": { - "define": true, - "jQuery": true, - "require": true - } -} diff --git a/Gruntfile.js b/Gruntfile.js index 3bc12c6..b90568b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,3 @@ -/*jshint node: true */ - 'use strict'; module.exports = function (grunt) { @@ -10,12 +8,52 @@ module.exports = function (grunt) { all: ['test/index.html'] }, jshint: { - files: [ - 'Gruntfile.js', - 'jquery.cookie.js' - ], options: { - jshintrc: true + curly: true, + eqeqeq: true, + expr: true, + // maxlen: 130, + newcap: true, + noarg: true, + nonbsp: true, + trailing: true, + undef: true, + unused: true + }, + grunt: { + options: { + node: true, + quotmark: 'single' + }, + files: { + src: ['Gruntfile.js'] + } + }, + source: { + options: { + browser: true, + camelcase: true, + jquery: true, + quotmark: 'single', + globals: { + define: true, + require: true + }, + }, + files: { + src: ['jquery.cookie.js'] + } + }, + tests: { + options: { + browser: true, + jquery: true, + qunit: true, + '-W053': true + }, + files: { + src: ['test/**/*.js'] + } } }, uglify: { @@ -34,7 +72,7 @@ module.exports = function (grunt) { }, files: [ 'jquery.cookie.js', - 'test/tests.js' + 'test/**/*.js' ], tasks: 'default' }, From 14557ed5dec32c317bbd426f20e5287a8b9c0f8f Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 2 Jun 2014 07:40:12 +0200 Subject: [PATCH 59/75] Simplifying test server url... --- CONTRIBUTING.md | 2 +- Gruntfile.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7ad0146..608c33e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ Start a test server from the project root: $ grunt connect:tests -This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser, with livereload enabled. +This will automatically open the test suite at http://127.0.0.1:9998 in the default browser, with livereload enabled. _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/Gruntfile.js b/Gruntfile.js index b90568b..fd08089 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -92,13 +92,15 @@ module.exports = function (grunt) { connect: { saucelabs: { options: { - port: 9999 + port: 9999, + base: ['.', 'test'] } }, tests: { options: { port: 9998, - open: 'http://127.0.0.1:9998/test/index.html', + base: ['.', 'test'], + open: 'http://127.0.0.1:9998', keepalive: true, livereload: true } @@ -107,7 +109,7 @@ module.exports = function (grunt) { 'saucelabs-qunit': { all: { options: { - urls: ['http://127.0.0.1:9999/test/index.html'], + urls: ['http://127.0.0.1:9999'], build: process.env.TRAVIS_JOB_ID, browsers: [ // iOS From be47cde2a75446930784fde3e15263974599fd16 Mon Sep 17 00:00:00 2001 From: Krinke Date: Sat, 12 Jul 2014 11:23:00 -0300 Subject: [PATCH 60/75] Invalid cookie value should not be a getter Closes gh-308. Closes gh-309. --- jquery.cookie.js | 2 +- test/tests.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index c7f3a59..be1c097 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -56,7 +56,7 @@ // Write - if (value !== undefined && !$.isFunction(value)) { + if (arguments.length > 1 && !$.isFunction(value)) { options = $.extend({}, config.defaults, options); if (typeof options.expires === 'number') { diff --git a/test/tests.js b/test/tests.js index 008f121..c016bce 100644 --- a/test/tests.js +++ b/test/tests.js @@ -194,6 +194,18 @@ test('number', function () { strictEqual($.cookie('c'), '1234', 'should write value'); }); +test('null', function () { + expect(1); + $.cookie('c', null); + strictEqual($.cookie('c'), 'null', 'should write value'); +}); + +test('undefined', function () { + expect(1); + $.cookie('c', undefined); + strictEqual($.cookie('c'), 'undefined', 'should write value'); +}); + test('expires option as days from now', function () { expect(1); var sevenDaysFromNow = new Date(); From b106a0e23640281321cf7ced832f6dc8fb88a085 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 14 Jul 2014 21:54:20 +0200 Subject: [PATCH 61/75] Move JSHint config to jshintrc files Follows-up 3f1f88b725. Also: * Moved jquery.cookie.js to src/ directory to allow using a separate configuration for it (also complements /build, and other jQuery plugin repositories). * Simplified Grunt configuration. --- .jshintignore | 2 + .jshintrc | 12 +++++ Gruntfile.js | 61 ++++-------------------- bower.json | 2 +- component.json | 4 +- src/.jshintrc | 12 +++++ jquery.cookie.js => src/jquery.cookie.js | 0 test/.jshintrc | 9 ++++ test/index.html | 2 +- test/malformed_cookie.html | 2 +- 10 files changed, 49 insertions(+), 57 deletions(-) create mode 100644 .jshintignore create mode 100644 .jshintrc create mode 100644 src/.jshintrc rename jquery.cookie.js => src/jquery.cookie.js (100%) create mode 100644 test/.jshintrc diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..e3fbd98 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,2 @@ +build +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..fd016db --- /dev/null +++ b/.jshintrc @@ -0,0 +1,12 @@ +{ + "curly": true, + "eqeqeq": true, + "expr": true, + // "maxlen": 130, + "newcap": true, + "noarg": true, + "nonbsp": true, + "trailing": true, + "undef": true, + "unused": true +} diff --git a/Gruntfile.js b/Gruntfile.js index fd08089..5ac9db5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,3 +1,4 @@ +/*jshint node:true, quotmark:single */ 'use strict'; module.exports = function (grunt) { @@ -5,56 +6,15 @@ module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), qunit: { - all: ['test/index.html'] + all: 'test/index.html' }, jshint: { options: { - curly: true, - eqeqeq: true, - expr: true, - // maxlen: 130, - newcap: true, - noarg: true, - nonbsp: true, - trailing: true, - undef: true, - unused: true + jshintrc: true }, - grunt: { - options: { - node: true, - quotmark: 'single' - }, - files: { - src: ['Gruntfile.js'] - } - }, - source: { - options: { - browser: true, - camelcase: true, - jquery: true, - quotmark: 'single', - globals: { - define: true, - require: true - }, - }, - files: { - src: ['jquery.cookie.js'] - } - }, - tests: { - options: { - browser: true, - jquery: true, - qunit: true, - '-W053': true - }, - files: { - src: ['test/**/*.js'] - } - } + grunt: 'Gruntfile.js', + source: 'src/**/*.js', + tests: 'test/**/*.js' }, uglify: { options: { @@ -62,7 +22,7 @@ module.exports = function (grunt) { }, build: { files: { - 'build/jquery.cookie-<%= pkg.version %>.min.js': 'jquery.cookie.js' + 'build/jquery.cookie-<%= pkg.version %>.min.js': 'src/jquery.cookie.js' } } }, @@ -70,16 +30,13 @@ module.exports = function (grunt) { options: { livereload: true }, - files: [ - 'jquery.cookie.js', - 'test/**/*.js' - ], + files: '{src,test}/**/*.js', tasks: 'default' }, compare_size: { files: [ 'build/jquery.cookie-<%= pkg.version %>.min.js', - 'jquery.cookie.js' + 'src/jquery.cookie.js' ], options: { compress: { diff --git a/bower.json b/bower.json index 2d8c25b..3862b74 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "jquery.cookie", "version": "1.4.1", "main": [ - "./jquery.cookie.js" + "src/jquery.cookie.js" ], "dependencies": { "jquery": ">=1.2" diff --git a/component.json b/component.json index 58f79d6..0fad480 100644 --- a/component.json +++ b/component.json @@ -7,8 +7,8 @@ "dependencies": {}, "development": {}, "license": "MIT", - "main": "jquery.cookie.js", + "main": "src/jquery.cookie.js", "scripts": [ - "jquery.cookie.js" + "src/jquery.cookie.js" ] } diff --git a/src/.jshintrc b/src/.jshintrc new file mode 100644 index 0000000..dcdf6d6 --- /dev/null +++ b/src/.jshintrc @@ -0,0 +1,12 @@ +{ + "browser": true, + "camelcase": true, + "jquery": true, + "quotmark": "single", + "globals": { + "define": true, + "require": true + }, + + "extends": "../.jshintrc" +} diff --git a/jquery.cookie.js b/src/jquery.cookie.js similarity index 100% rename from jquery.cookie.js rename to src/jquery.cookie.js diff --git a/test/.jshintrc b/test/.jshintrc new file mode 100644 index 0000000..bc52b0a --- /dev/null +++ b/test/.jshintrc @@ -0,0 +1,9 @@ +{ + "browser": true, + "jquery": true, + "qunit": true, + + "-W053": true, + + "extends": "../.jshintrc" +} diff --git a/test/index.html b/test/index.html index 841310b..ade6830 100644 --- a/test/index.html +++ b/test/index.html @@ -6,7 +6,7 @@ - + diff --git a/test/malformed_cookie.html b/test/malformed_cookie.html index 17e8db8..74178d4 100644 --- a/test/malformed_cookie.html +++ b/test/malformed_cookie.html @@ -3,7 +3,7 @@ - +