From e27bb9fc2c215d1093ae256de240d85bd219e75c Mon Sep 17 00:00:00 2001 From: maxbronnikov10 Date: Mon, 15 Jul 2024 19:53:01 +0300 Subject: [PATCH] fix: Is serialized broken check --- src/isSerialized.ts | 7 ++----- test/isSerialized-test.ts | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/isSerialized.ts b/src/isSerialized.ts index b2e4e96..85de850 100644 --- a/src/isSerialized.ts +++ b/src/isSerialized.ts @@ -46,6 +46,8 @@ export default function isSerialized(givenItem: string, strict = false) { switch (token) { case 's': + case 'a': + case 'O': if (strict) { if (item.substr(-2, 1) !== '"') { return false @@ -53,12 +55,7 @@ export default function isSerialized(givenItem: string, strict = false) { } else if (item.indexOf('"') === -1) { return false } - break - - // or else fall through - case 'a': - case 'O': return item.match(new RegExp(`^${token}:[0-9]+:`, 's')) !== null case 'b': diff --git a/test/isSerialized-test.ts b/test/isSerialized-test.ts index 3d03eba..4c1edf0 100644 --- a/test/isSerialized-test.ts +++ b/test/isSerialized-test.ts @@ -4,6 +4,7 @@ import { isSerialized } from '..' test('test whether the content is legitimate serialized content', t => { t.is(isSerialized('a:1:{i:0;s:12:"add-post_tag";}'), true) t.is(isSerialized('d:100010001000100004049513873408;'), true) + t.is(isSerialized('s:3276:"{"a":1}";'), true) t.is(isSerialized('i:100000000;'), true) t.is(isSerialized('d:1.7976931348623157E+308;'), true) t.is(isSerialized('something'), false)