Skip to content

Commit bbc0914

Browse files
committed
fix(cookie): 修复 cookieParse 解析 value 包含 = 时会丢失后半部分的问题
1 parent f275e42 commit bbc0914

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/common/cookie.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('cookie.ts', () => {
1313
['a=1;b=b', { a: '1', b: 'b' }],
1414
['a=;b=b', { a: '', b: 'b' }],
1515
['a=%E6%B5%8B%E8%AF%95001;b=b', { a: '测试001', b: 'b' }],
16+
['a=%E6%B5%8B%E8%AF%95001=123;b=b', { a: '测试001=123', b: 'b' }],
1617
] as const;
1718
for (const [cookie, obj] of list) {
1819
expect(cookieParse(cookie as never)).toEqual(obj);

src/common/cookie.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: renxia
33
* @Date: 2024-01-15 11:26:52
44
* @LastEditors: renxia
5-
* @LastEditTime: 2024-01-16 16:38:39
5+
* @LastEditTime: 2024-07-24 11:38:51
66
* @Description: cookie 相关处理工具方法
77
*/
88

@@ -14,7 +14,9 @@ export function cookieParse(cookie = '', filterNilValue = false) {
1414

1515
if (typeof cookie === 'string' && cookie.length > 0) {
1616
for (const d of cookie.split(';')) {
17-
const [key, value] = d.split('=').map(d => d.trim());
17+
const arr = d.split('=');
18+
const key = arr[0].trim();
19+
const value = arr.slice(1).join('=').trim();
1820
if (filterNilValue && !value) continue;
1921

2022
try {

0 commit comments

Comments
 (0)