Skip to content

Commit

Permalink
Merge pull request #300 from maxbronnikov10/fix/is-serialized-check
Browse files Browse the repository at this point in the history
fix: Is serialized broken check
  • Loading branch information
steelbrain authored Jul 15, 2024
2 parents 322c9cd + e27bb9f commit 41c8666
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/isSerialized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@ 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
}
} 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':
Expand Down
1 change: 1 addition & 0 deletions test/isSerialized-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 41c8666

Please sign in to comment.