Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
URL decoding of raw cookie header key-value pairs as recommended by h…
  • Loading branch information
barakshechter committed Jul 15, 2019
commit e5b9f9fcde9858dcebe6ae558cee8f11acb40f2d
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ Cookies.prototype.get = function(name, opts) {
match = header.match(getPattern(name))
if (!match) return

value = match[1]
/*
* https://tools.ietf.org/html/rfc6265#section-4.1.1
*
* To maximize compatibility with user agents, servers that wish to
* store arbitrary data in a cookie-value SHOULD encode that data, for
* example, using Base64 [RFC4648].
*/
value = decodeURIComponent(match[1])
if (!opts || !signed) return value

remote = this.get(sigName)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cookies",
"description": "Cookies, optionally signed using Keygrip.",
"version": "0.7.3",
"version": "0.7.4",
"author": "Jed Schmidt <tr@nslator.jp> (http://jed.is)",
"contributors": [
"Douglas Christopher Wilson <doug@somethingdoug.com>"
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ describe('new Cookies(req, res, [options])', function () {
res.end(String(cookies.get('foo')))
}))
.get('/')
.set('Cookie', 'foo=bar')
.expect(200, 'bar', done)
.set('Cookie', 'foo=bar%3D')
.expect(200, 'bar=', done)
})

it('should work for cookie name with special characters', function (done) {
Expand Down