Skip to content

Commit

Permalink
Revert "Remove dealing with quoted cookie values"
Browse files Browse the repository at this point in the history
This reverts commit d1b0b31.
  • Loading branch information
carhartl committed Sep 8, 2020
1 parent 61972e1 commit 3d56250
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function init (converter, defaultAttributes) {
var parts = cookies[i].split('=')
var value = parts.slice(1).join('=')

if (value[0] === '"') {
value = value.slice(1, -1)
}

try {
var foundKey = defaultConverter.read(parts[0])
jar[foundKey] = converter.read(value, foundKey)
Expand Down
12 changes: 12 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ QUnit.test('Call to read all when there are no cookies at all', function (
assert.deepEqual(Cookies.get(), {}, 'returns empty object')
})

QUnit.test('RFC 6265 - reading cookie-octet enclosed in DQUOTE', function (
assert
) {
assert.expect(1)
document.cookie = 'c="v"'
assert.strictEqual(
Cookies.get('c'),
'v',
'should simply ignore quoted strings'
)
})

// github.com/js-cookie/js-cookie/issues/196
QUnit.test(
'Call to read cookie when there is another unrelated cookie with malformed encoding in the name',
Expand Down

0 comments on commit 3d56250

Please sign in to comment.