simple-cookie
Advanced tools
Comparing version 0.0.5 to 0.0.6
19
index.js
@@ -23,3 +23,4 @@ function printExpires(expires){ | ||
parse: function( string, path, domain ){ | ||
var s = string.replace(/;\s+/,';').split(';').map(function(s){return s.split('=');}); | ||
var s = string.replace(/;\s+/g,';').split(';') | ||
.map(function(s){return s.replace(/\s+\=\s+/g,'=').split('=');}); | ||
@@ -30,6 +31,10 @@ var n = s.shift(); | ||
obj.expires = false; | ||
obj.httponly = false; | ||
obj.secure = false; | ||
obj.path = path || '/'; | ||
obj.domain = domain || ''; | ||
var I, f = { | ||
'httponly': function(v){ obj.httponly = true }, | ||
'secure': function(v){ obj.secure = true }, | ||
'httponly': function(){ obj.httponly = true }, | ||
'secure': function(){ obj.secure = true }, | ||
'expires': function(v){ obj.expires = new Date(v) }, | ||
@@ -43,10 +48,6 @@ 'max-age': function(v){ if(obj.expires) return; obj.expires = new Date((new Date()).valueOf()+(v*1000)) }, | ||
I = s[i][0].toLowerCase(); | ||
if( typeof f[I] != 'undefined' ) f[I]( s[i][1] ); | ||
if( typeof f[I] != 'undefined' ) f[I]( s[i].length==2 ? s[i][1] : '' ); | ||
} | ||
if( typeof obj.httponly == 'undefined' ) obj.httponly = false; | ||
if( typeof obj.secure == 'undefined' ) obj.secure = false; | ||
if( typeof obj.path == 'undefined' ) obj.path = path || '/'; | ||
if( typeof obj.domain == 'undefined' ) obj.domain = domain || ''; | ||
if( typeof obj.expires == 'undefined' || !obj.expires ) obj.expires = 0; | ||
if( !obj.expires ) obj.expires = 0; | ||
obj.name = n[0]; | ||
@@ -53,0 +54,0 @@ obj.value = decodeURIComponent(n[1]); |
{ | ||
"name": "simple-cookie", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Simple cookie parser & serializer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,2 +11,3 @@ | ||
var co; | ||
var date = (new Date((new Date()).valueOf() + 3000)).toGMTString(); | ||
@@ -40,2 +41,21 @@ describe('simple-cookie',function(){ | ||
describe('#parseString',function(){ | ||
it("should return the right object from cookie string",function(){ | ||
var theCookie = 'cnameSecure=cval1sec; expires='+date+ | ||
'; domain=.example.com; path=/; secure'; | ||
var h = cookie.parse( theCookie, 'example.com', '/is/cool' ); | ||
h.name.should.equal( 'cnameSecure' ); | ||
h.value.should.equal( 'cval1sec' ); | ||
h.expires.should.be.a( 'date' ); | ||
h.expires.toGMTString().should.equal( date ); | ||
h.secure.should.equal( true ); | ||
h.httponly.should.equal( false ); | ||
h.path.should.equal( '/' ); | ||
h.domain.should.equal( '.example.com' ); | ||
}); | ||
}); | ||
describe('#tokeninze',function(){ | ||
@@ -52,3 +72,2 @@ it('should return tokenized cookies ready to send', function(){ | ||
var h = cookie.tokenize(cc); | ||
console.log(h); | ||
h.should.be.a('string'); | ||
@@ -55,0 +74,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5890
103