Skip to content

Commit 214a23e

Browse files
Update the snippet to decode plus sign to spaces first
Otherwise "legit" encoded pluses will be replaced incorrectly This is based on @nanaya's comment at js-cookie#70 (comment)
1 parent 7a73bd2 commit 214a23e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

SERVER_SIDE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ var PHPCookies = Cookies.withConverter({
3636
},
3737
read: function (value) {
3838
return value
39-
// Decode all characters according to the "encodeURIComponent" spec
40-
.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent)
41-
// Decode the plus sign to spaces
39+
// Decode the plus sign to spaces first, otherwise "legit" encoded pluses
40+
// will be replaced incorrectly
4241
.replace(/\+/g, ' ')
42+
// Decode all characters according to the "encodeURIComponent" spec
43+
.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
4344
}
4445
});
4546
```

0 commit comments

Comments
 (0)