From bbc0914c5e9ccc25378717baec5eab1c24fed121 Mon Sep 17 00:00:00 2001 From: renxia Date: Wed, 24 Jul 2024 11:41:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(cookie):=20=E4=BF=AE=E5=A4=8D=20cookieParse?= =?UTF-8?q?=20=E8=A7=A3=E6=9E=90=20value=20=E5=8C=85=E5=90=AB=20=3D=20?= =?UTF-8?q?=E6=97=B6=E4=BC=9A=E4=B8=A2=E5=A4=B1=E5=90=8E=E5=8D=8A=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/cookie.spec.ts | 1 + src/common/cookie.ts | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/cookie.spec.ts b/src/common/cookie.spec.ts index f36e54d..c59febb 100644 --- a/src/common/cookie.spec.ts +++ b/src/common/cookie.spec.ts @@ -13,6 +13,7 @@ describe('cookie.ts', () => { ['a=1;b=b', { a: '1', b: 'b' }], ['a=;b=b', { a: '', b: 'b' }], ['a=%E6%B5%8B%E8%AF%95001;b=b', { a: '测试001', b: 'b' }], + ['a=%E6%B5%8B%E8%AF%95001=123;b=b', { a: '测试001=123', b: 'b' }], ] as const; for (const [cookie, obj] of list) { expect(cookieParse(cookie as never)).toEqual(obj); diff --git a/src/common/cookie.ts b/src/common/cookie.ts index ea6d7ea..c244f58 100644 --- a/src/common/cookie.ts +++ b/src/common/cookie.ts @@ -2,7 +2,7 @@ * @Author: renxia * @Date: 2024-01-15 11:26:52 * @LastEditors: renxia - * @LastEditTime: 2024-01-16 16:38:39 + * @LastEditTime: 2024-07-24 11:38:51 * @Description: cookie 相关处理工具方法 */ @@ -14,7 +14,9 @@ export function cookieParse(cookie = '', filterNilValue = false) { if (typeof cookie === 'string' && cookie.length > 0) { for (const d of cookie.split(';')) { - const [key, value] = d.split('=').map(d => d.trim()); + const arr = d.split('='); + const key = arr[0].trim(); + const value = arr.slice(1).join('=').trim(); if (filterNilValue && !value) continue; try {