Skip to content

Commit 13f5145

Browse files
Need to use global replace (damn "g")
1 parent 5ac2a2a commit 13f5145

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/js.cookie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
value = value.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
8787

8888
key = encodeURIComponent(String(key));
89-
key = key.replace(/%(23|24|26|2B|5E|60|7C)/, decodeURIComponent);
89+
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
9090
key = key.replace(/[\(\)]/g, escape);
9191

9292
return (document.cookie = [

test/encoding.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test('RFC 6265 - character allowed in the cookie-value "|"', function () {
189189
strictEqual(document.cookie, 'c=|', 'pipe is allowed, should not encode');
190190
});
191191

192-
test('RFC 6265 - characters allowed in the cookie-value should not be encoded globally', function () {
192+
test('RFC 6265 - characters allowed in the cookie-value should globally not be encoded', function () {
193193
expect(1);
194194
Cookies.set('c', '{{');
195195
strictEqual(document.cookie, 'c={{', 'should not encode all the character occurrences');
@@ -410,6 +410,12 @@ test('RFC 6265 - character allowed in the cookie-name "|"', function () {
410410
strictEqual(document.cookie, '|=v', 'pipe is allowed, should not encode');
411411
});
412412

413+
test('RFC 6265 - characters allowed in the cookie-name should globally not be encoded', function () {
414+
expect(1);
415+
Cookies.set('||', 'v');
416+
strictEqual(document.cookie, '||=v', 'should not encode all character occurrences');
417+
});
418+
413419
test('cookie-name - 2 bytes characters', function () {
414420
expect(2);
415421

0 commit comments

Comments
 (0)