Skip to content

Commit

Permalink
fix: Is serialized broken check
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbronnikov10 committed Jul 15, 2024
1 parent 322c9cd commit e27bb9f
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 e27bb9f

Please sign in to comment.