Merge branch 'master' into encoding
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Aaron Heckmann · committed by Aaron Heckmann · parents 4e68705, 5dc152c · Browse files · 3 files·+33 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+33 added−9 removed
- tests:+17 added−2 removed
- other:+16 added−7 removed
Provenance
- Commit
1aed6b5- Tree
5258e35- Author
Aaron Heckmann <aaron.heckmann@gmail.com>- Committer
Aaron Heckmann <aaron.heckmann@gmail.com>- Parent 1
4e68705- Parent 2
5dc152c
3 files changed+33 added−9 removed
modified:lib/express/plugins/cookie.js+16 added-7 removed
3 unmodified lines4567889101112132 unmodified lines16171819192021222021222324252627282930313233343587 unmodified lines1231241251261181271281291211303 unmodified lines/** * Module dependencies. */ var Request = require('express/request').Requestvar Request = require('express/request').Request, queryString = require('querystring')
/** * Parse an HTTP _cookie_ string into a hash. *2 unmodified lines * @api public */
exports.parseCookie = function(cookie) { return cookie.replace(/^ *| *$/g, '').split(/ *; */).reduce(function(hash, pair){ var parts = pair.split(/ *= */) hash[parts[0]] = parts[1] return hash return cookie.split(/[;,] */).reduce(function(cookies, pair) { var eql = pair.indexOf('=') if (eql === -1) return cookies var key = queryString.unescape(pair.slice(0, eql).trim(), true) var val = queryString.unescape(pair.slice(eql + 1).trim(), true) var captures = val.match(/^("|')([^\1]*)\1$/) if (captures) val = captures[2].replace('\\' + captures[1], captures[1]) //RFC2109 states the most specific path will be //listed first if (cookies[key] === undefined) cookies[key] = val return cookies }, {})}
/**87 unmodified lines response: function(event) { if (event.response.cookies && event.response.cookies.length) event.request.header('Set-Cookie', event.response.cookies.join('\nSet-Cookie: ')) event.request.header('Set-Cookie', event.response.cookies.join('\r\nSet-Cookie: ')) } }})No newline at end of file})modified:lib/support/hamlnot shown
Its text is not shown, modified.
modified:spec/spec.plugins.cookie.js+17 added-2 removed
53 unmodified lines54 it 'should disregard ad-hoc invalid whitespace'55 var attrs = ' SID = 1232431234234 ; data = foo'56 parseCookie(attrs).should.eql { SID: '1232431234234', data: 'foo' }57 end58+59+ it 'should support complex quoted values'60+ var attrs = 'SID="123456789"; fbs_0011223355="uid=0987654321&name=Test+User"'61+ parseCookie(attrs).should.eql { SID: '123456789', fbs_0011223355: 'uid=0987654321&name=Test User' }62+ end63+ 64+ it 'should not override when a duplicate key is found'65+ var attrs = 'SID=1234; SID=9999'66+ parseCookie(attrs).should.eql { SID: '1234' }67+ end68+ 69+ it 'should support malformed cookies'70+ var attrs = 'SID'71+ parseCookie(attrs).should.eql {}72+ end73 end74 75 describe 'on'76 describe 'request'19 unmodified lines96 this.cookie('SID', '732423sdfs73243', { path: '/', secure: true })97 this.cookie('foo', 'bar')98 return '' 99 })85- get('/user').headers['Set-Cookie'].should.eql 'SID=732423sdfs73243; path=/; secure\nSet-Cookie: foo=bar; path=/'100+ get('/user').headers['Set-Cookie'].should.eql 'SID=732423sdfs73243; path=/; secure\r\nSet-Cookie: foo=bar; path=/'101 end102 end103 end104 6 unmodified lines111 end112 end113 114 end100-end115+end