locutus 2.0.12 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_util/cli.js.map +1 -1
- package/_util/util.js +11 -16
- package/_util/util.js.map +1 -1
- package/c/index.js +2 -2
- package/c/index.js.map +1 -1
- package/c/math/index.js +2 -2
- package/c/math/index.js.map +1 -1
- package/c/stdio/index.js +1 -1
- package/c/stdio/index.js.map +1 -1
- package/c/stdio/sprintf.js +8 -1
- package/c/stdio/sprintf.js.map +1 -1
- package/golang/index.js +1 -1
- package/golang/index.js.map +1 -1
- package/golang/strings/Count.js +1 -1
- package/golang/strings/Count.js.map +1 -1
- package/golang/strings/index.js +4 -4
- package/golang/strings/index.js.map +1 -1
- package/index.js +5 -5
- package/index.js.map +1 -1
- package/package.json +39 -40
- package/php/_helpers/_bc.js +104 -48
- package/php/_helpers/_bc.js.map +1 -1
- package/php/_helpers/_phpCastString.js.map +1 -1
- package/php/_helpers/_php_cast_float.js.map +1 -1
- package/php/_helpers/_php_cast_int.js.map +1 -1
- package/php/_helpers/index.js +4 -4
- package/php/_helpers/index.js.map +1 -1
- package/php/array/array_change_key_case.js +2 -2
- package/php/array/array_change_key_case.js.map +1 -1
- package/php/array/array_chunk.js +1 -1
- package/php/array/array_chunk.js.map +1 -1
- package/php/array/array_column.js.map +1 -1
- package/php/array/array_combine.js.map +1 -1
- package/php/array/array_count_values.js.map +1 -1
- package/php/array/array_diff.js.map +1 -1
- package/php/array/array_diff_assoc.js.map +1 -1
- package/php/array/array_diff_key.js.map +1 -1
- package/php/array/array_diff_uassoc.js.map +1 -1
- package/php/array/array_diff_ukey.js.map +1 -1
- package/php/array/array_fill.js +1 -1
- package/php/array/array_fill.js.map +1 -1
- package/php/array/array_fill_keys.js.map +1 -1
- package/php/array/array_filter.js +1 -1
- package/php/array/array_filter.js.map +1 -1
- package/php/array/array_flip.js +1 -1
- package/php/array/array_flip.js.map +1 -1
- package/php/array/array_intersect.js.map +1 -1
- package/php/array/array_intersect_assoc.js.map +1 -1
- package/php/array/array_intersect_key.js.map +1 -1
- package/php/array/array_intersect_uassoc.js.map +1 -1
- package/php/array/array_intersect_ukey.js.map +1 -1
- package/php/array/array_keys.js.map +1 -1
- package/php/array/array_map.js.map +1 -1
- package/php/array/array_merge.js +1 -1
- package/php/array/array_merge.js.map +1 -1
- package/php/array/array_merge_recursive.js.map +1 -1
- package/php/array/array_multisort.js +16 -16
- package/php/array/array_multisort.js.map +1 -1
- package/php/array/array_pad.js +1 -1
- package/php/array/array_pad.js.map +1 -1
- package/php/array/array_pop.js.map +1 -1
- package/php/array/array_product.js.map +1 -1
- package/php/array/array_push.js.map +1 -1
- package/php/array/array_rand.js.map +1 -1
- package/php/array/array_reduce.js.map +1 -1
- package/php/array/array_replace.js.map +1 -1
- package/php/array/array_replace_recursive.js +1 -1
- package/php/array/array_replace_recursive.js.map +1 -1
- package/php/array/array_reverse.js +1 -1
- package/php/array/array_reverse.js.map +1 -1
- package/php/array/array_search.js.map +1 -1
- package/php/array/array_shift.js +0 -19
- package/php/array/array_shift.js.map +1 -1
- package/php/array/array_slice.js.map +1 -1
- package/php/array/array_splice.js.map +1 -1
- package/php/array/array_sum.js +1 -1
- package/php/array/array_sum.js.map +1 -1
- package/php/array/array_udiff.js.map +1 -1
- package/php/array/array_udiff_assoc.js.map +1 -1
- package/php/array/array_udiff_uassoc.js.map +1 -1
- package/php/array/array_uintersect.js.map +1 -1
- package/php/array/array_uintersect_uassoc.js.map +1 -1
- package/php/array/array_unique.js.map +1 -1
- package/php/array/array_unshift.js.map +1 -1
- package/php/array/array_values.js.map +1 -1
- package/php/array/array_walk.js.map +1 -1
- package/php/array/array_walk_recursive.js.map +1 -1
- package/php/array/arsort.js +3 -3
- package/php/array/arsort.js.map +1 -1
- package/php/array/asort.js +3 -3
- package/php/array/asort.js.map +1 -1
- package/php/array/count.js +1 -1
- package/php/array/count.js.map +1 -1
- package/php/array/current.js.map +1 -1
- package/php/array/each.js.map +1 -1
- package/php/array/end.js +1 -1
- package/php/array/end.js.map +1 -1
- package/php/array/in_array.js.map +1 -1
- package/php/array/index.js +73 -72
- package/php/array/index.js.map +1 -1
- package/php/array/key.js.map +1 -1
- package/php/array/krsort.js +3 -3
- package/php/array/krsort.js.map +1 -1
- package/php/array/ksort.js +3 -3
- package/php/array/ksort.js.map +1 -1
- package/php/array/natcasesort.js +2 -2
- package/php/array/natcasesort.js.map +1 -1
- package/php/array/natsort.js +2 -2
- package/php/array/natsort.js.map +1 -1
- package/php/array/next.js.map +1 -1
- package/php/array/pos.js.map +1 -1
- package/php/array/prev.js.map +1 -1
- package/php/array/range.js +3 -3
- package/php/array/range.js.map +1 -1
- package/php/array/reset.js.map +1 -1
- package/php/array/rsort.js +3 -3
- package/php/array/rsort.js.map +1 -1
- package/php/array/shuffle.js.map +1 -1
- package/php/array/sizeof.js.map +1 -1
- package/php/array/sort.js +3 -3
- package/php/array/sort.js.map +1 -1
- package/php/array/uasort.js.map +1 -1
- package/php/array/uksort.js.map +1 -1
- package/php/array/usort.js.map +1 -1
- package/php/bc/bcadd.js +3 -1
- package/php/bc/bcadd.js.map +1 -1
- package/php/bc/bccomp.js +2 -1
- package/php/bc/bccomp.js.map +1 -1
- package/php/bc/bcdiv.js +3 -1
- package/php/bc/bcdiv.js.map +1 -1
- package/php/bc/bcmul.js +3 -1
- package/php/bc/bcmul.js.map +1 -1
- package/php/bc/bcround.js +4 -2
- package/php/bc/bcround.js.map +1 -1
- package/php/bc/bcscale.js.map +1 -1
- package/php/bc/bcsub.js +3 -1
- package/php/bc/bcsub.js.map +1 -1
- package/php/bc/index.js +7 -7
- package/php/bc/index.js.map +1 -1
- package/php/ctype/ctype_alnum.js.map +1 -1
- package/php/ctype/ctype_alpha.js.map +1 -1
- package/php/ctype/ctype_cntrl.js.map +1 -1
- package/php/ctype/ctype_digit.js.map +1 -1
- package/php/ctype/ctype_graph.js.map +1 -1
- package/php/ctype/ctype_lower.js.map +1 -1
- package/php/ctype/ctype_print.js.map +1 -1
- package/php/ctype/ctype_punct.js.map +1 -1
- package/php/ctype/ctype_space.js.map +1 -1
- package/php/ctype/ctype_upper.js.map +1 -1
- package/php/ctype/ctype_xdigit.js.map +1 -1
- package/php/ctype/index.js +11 -11
- package/php/ctype/index.js.map +1 -1
- package/php/datetime/date.js +2 -1
- package/php/datetime/date.js.map +1 -1
- package/php/datetime/date_parse.js +1 -1
- package/php/datetime/date_parse.js.map +1 -1
- package/php/datetime/getdate.js.map +1 -1
- package/php/datetime/gettimeofday.js.map +1 -1
- package/php/datetime/gmdate.js.map +1 -1
- package/php/datetime/gmmktime.js.map +1 -1
- package/php/datetime/gmstrftime.js.map +1 -1
- package/php/datetime/idate.js +1 -1
- package/php/datetime/idate.js.map +1 -1
- package/php/datetime/index.js +15 -15
- package/php/datetime/index.js.map +1 -1
- package/php/datetime/microtime.js +3 -3
- package/php/datetime/microtime.js.map +1 -1
- package/php/datetime/mktime.js.map +1 -1
- package/php/datetime/strftime.js +2 -3
- package/php/datetime/strftime.js.map +1 -1
- package/php/datetime/strptime.js +20 -21
- package/php/datetime/strptime.js.map +1 -1
- package/php/datetime/strtotime.js +170 -4
- package/php/datetime/strtotime.js.map +1 -1
- package/php/exec/escapeshellarg.js +12 -4
- package/php/exec/escapeshellarg.js.map +1 -1
- package/php/exec/index.js +1 -1
- package/php/exec/index.js.map +1 -1
- package/php/filesystem/basename.js.map +1 -1
- package/php/filesystem/file_get_contents.js.map +1 -1
- package/php/filesystem/index.js +5 -5
- package/php/filesystem/index.js.map +1 -1
- package/php/filesystem/pathinfo.js +7 -8
- package/php/filesystem/pathinfo.js.map +1 -1
- package/php/filesystem/realpath.js.map +1 -1
- package/php/funchand/call_user_func.js.map +1 -1
- package/php/funchand/call_user_func_array.js +1 -1
- package/php/funchand/call_user_func_array.js.map +1 -1
- package/php/funchand/function_exists.js.map +1 -1
- package/php/funchand/get_defined_functions.js.map +1 -1
- package/php/funchand/index.js +5 -5
- package/php/funchand/index.js.map +1 -1
- package/php/i18n/i18n_loc_get_default.js.map +1 -1
- package/php/i18n/i18n_loc_set_default.js.map +1 -1
- package/php/i18n/index.js +2 -2
- package/php/i18n/index.js.map +1 -1
- package/php/index.js +19 -19
- package/php/index.js.map +1 -1
- package/php/info/assert_options.js +2 -1
- package/php/info/assert_options.js.map +1 -1
- package/php/info/index.js +6 -6
- package/php/info/index.js.map +1 -1
- package/php/info/ini_get.js.map +1 -1
- package/php/info/ini_set.js.map +1 -1
- package/php/info/set_time_limit.js.map +1 -1
- package/php/info/version_compare.js +21 -22
- package/php/info/version_compare.js.map +1 -1
- package/php/json/index.js +3 -3
- package/php/json/index.js.map +1 -1
- package/php/json/json_decode.js +1 -1
- package/php/json/json_decode.js.map +1 -1
- package/php/json/json_encode.js +1 -1
- package/php/json/json_encode.js.map +1 -1
- package/php/json/json_last_error.js.map +1 -1
- package/php/math/fmod.js +2 -2
- package/php/math/fmod.js.map +1 -1
- package/php/math/hypot.js.map +1 -1
- package/php/math/index.js +46 -46
- package/php/math/index.js.map +1 -1
- package/php/math/is_finite.js.map +1 -1
- package/php/math/is_infinite.js.map +1 -1
- package/php/math/is_nan.js.map +1 -1
- package/php/math/log1p.js.map +1 -1
- package/php/math/max.js +7 -7
- package/php/math/max.js.map +1 -1
- package/php/math/min.js +5 -5
- package/php/math/min.js.map +1 -1
- package/php/math/mt_rand.js.map +1 -1
- package/php/math/rand.js.map +1 -1
- package/php/math/round.js +1 -1
- package/php/math/round.js.map +1 -1
- package/php/misc/index.js +2 -2
- package/php/misc/index.js.map +1 -1
- package/php/misc/pack.js +23 -18
- package/php/misc/pack.js.map +1 -1
- package/php/misc/uniqid.js +1 -1
- package/php/misc/uniqid.js.map +1 -1
- package/php/net-gopher/gopher_parsedir.js +3 -4
- package/php/net-gopher/gopher_parsedir.js.map +1 -1
- package/php/net-gopher/index.js +1 -1
- package/php/net-gopher/index.js.map +1 -1
- package/php/network/index.js +6 -6
- package/php/network/index.js.map +1 -1
- package/php/network/inet_ntop.js.map +1 -1
- package/php/network/inet_pton.js +40 -32
- package/php/network/inet_pton.js.map +1 -1
- package/php/network/setcookie.js.map +1 -1
- package/php/network/setrawcookie.js.map +1 -1
- package/php/pcre/index.js +4 -3
- package/php/pcre/index.js.map +1 -1
- package/php/pcre/preg_replace.js +24 -0
- package/php/pcre/preg_replace.js.map +1 -0
- package/php/pcre/sql_regcase.js.map +1 -1
- package/php/strings/addcslashes.js.map +1 -1
- package/php/strings/bin2hex.js +3 -3
- package/php/strings/bin2hex.js.map +1 -1
- package/php/strings/chop.js.map +1 -1
- package/php/strings/convert_cyr_string.js +1 -1
- package/php/strings/convert_cyr_string.js.map +1 -1
- package/php/strings/convert_uuencode.js.map +1 -1
- package/php/strings/count_chars.js +1 -1
- package/php/strings/count_chars.js.map +1 -1
- package/php/strings/crc32.js.map +1 -1
- package/php/strings/echo.js.map +1 -1
- package/php/strings/explode.js.map +1 -1
- package/php/strings/get_html_translation_table.js +1 -1
- package/php/strings/get_html_translation_table.js.map +1 -1
- package/php/strings/hex2bin.js +1 -1
- package/php/strings/hex2bin.js.map +1 -1
- package/php/strings/html_entity_decode.js.map +1 -1
- package/php/strings/htmlentities.js.map +1 -1
- package/php/strings/htmlspecialchars.js +6 -6
- package/php/strings/htmlspecialchars.js.map +1 -1
- package/php/strings/htmlspecialchars_decode.js +6 -6
- package/php/strings/htmlspecialchars_decode.js.map +1 -1
- package/php/strings/implode.js.map +1 -1
- package/php/strings/index.js +91 -91
- package/php/strings/index.js.map +1 -1
- package/php/strings/join.js.map +1 -1
- package/php/strings/lcfirst.js.map +1 -1
- package/php/strings/levenshtein.js +6 -1
- package/php/strings/levenshtein.js.map +1 -1
- package/php/strings/localeconv.js.map +1 -1
- package/php/strings/ltrim.js.map +1 -1
- package/php/strings/md5.js +19 -15
- package/php/strings/md5.js.map +1 -1
- package/php/strings/md5_file.js.map +1 -1
- package/php/strings/metaphone.js +2 -2
- package/php/strings/metaphone.js.map +1 -1
- package/php/strings/money_format.js.map +1 -1
- package/php/strings/nl2br.js.map +1 -1
- package/php/strings/nl_langinfo.js.map +1 -1
- package/php/strings/number_format.js.map +1 -1
- package/php/strings/ord.js.map +1 -1
- package/php/strings/parse_str.js +13 -13
- package/php/strings/parse_str.js.map +1 -1
- package/php/strings/printf.js.map +1 -1
- package/php/strings/quoted_printable_decode.js.map +1 -1
- package/php/strings/quoted_printable_encode.js.map +1 -1
- package/php/strings/rtrim.js.map +1 -1
- package/php/strings/setlocale.js +18 -19
- package/php/strings/setlocale.js.map +1 -1
- package/php/strings/sha1.js +12 -7
- package/php/strings/sha1.js.map +1 -1
- package/php/strings/sha1_file.js.map +1 -1
- package/php/strings/similar_text.js +4 -4
- package/php/strings/similar_text.js.map +1 -1
- package/php/strings/soundex.js +3 -3
- package/php/strings/soundex.js.map +1 -1
- package/php/strings/split.js.map +1 -1
- package/php/strings/sprintf.js +7 -2
- package/php/strings/sprintf.js.map +1 -1
- package/php/strings/sscanf.js +2 -2
- package/php/strings/sscanf.js.map +1 -1
- package/php/strings/str_getcsv.js +2 -2
- package/php/strings/str_getcsv.js.map +1 -1
- package/php/strings/str_ireplace.js +6 -0
- package/php/strings/str_ireplace.js.map +1 -1
- package/php/strings/str_pad.js +1 -1
- package/php/strings/str_pad.js.map +1 -1
- package/php/strings/str_repeat.js.map +1 -1
- package/php/strings/str_replace.js +6 -0
- package/php/strings/str_replace.js.map +1 -1
- package/php/strings/str_shuffle.js +1 -1
- package/php/strings/str_shuffle.js.map +1 -1
- package/php/strings/str_split.js.map +1 -1
- package/php/strings/str_word_count.js.map +1 -1
- package/php/strings/strcasecmp.js.map +1 -1
- package/php/strings/strchr.js.map +1 -1
- package/php/strings/strcoll.js.map +1 -1
- package/php/strings/strip_tags.js.map +1 -1
- package/php/strings/stripos.js.map +1 -1
- package/php/strings/stristr.js.map +1 -1
- package/php/strings/strlen.js.map +1 -1
- package/php/strings/strnatcasecmp.js.map +1 -1
- package/php/strings/strnatcmp.js.map +1 -1
- package/php/strings/strncasecmp.js +1 -1
- package/php/strings/strncasecmp.js.map +1 -1
- package/php/strings/strncmp.js.map +1 -1
- package/php/strings/strpbrk.js.map +1 -1
- package/php/strings/strpos.js.map +1 -1
- package/php/strings/strrchr.js.map +1 -1
- package/php/strings/strrev.js.map +1 -1
- package/php/strings/strripos.js.map +1 -1
- package/php/strings/strrpos.js.map +1 -1
- package/php/strings/strspn.js +3 -3
- package/php/strings/strspn.js.map +1 -1
- package/php/strings/strstr.js.map +1 -1
- package/php/strings/strtok.js.map +1 -1
- package/php/strings/strtr.js.map +1 -1
- package/php/strings/substr.js.map +1 -1
- package/php/strings/substr_count.js.map +1 -1
- package/php/strings/trim.js.map +1 -1
- package/php/strings/ucfirst.js.map +1 -1
- package/php/strings/vprintf.js.map +1 -1
- package/php/strings/vsprintf.js.map +1 -1
- package/php/strings/wordwrap.js +4 -2
- package/php/strings/wordwrap.js.map +1 -1
- package/php/url/base64_decode.js +8 -8
- package/php/url/base64_decode.js.map +1 -1
- package/php/url/base64_encode.js +8 -8
- package/php/url/base64_encode.js.map +1 -1
- package/php/url/http_build_query.js +4 -4
- package/php/url/http_build_query.js.map +1 -1
- package/php/url/index.js +8 -8
- package/php/url/index.js.map +1 -1
- package/php/url/parse_url.js +1 -1
- package/php/url/parse_url.js.map +1 -1
- package/php/var/doubleval.js.map +1 -1
- package/php/var/empty.js +4 -4
- package/php/var/empty.js.map +1 -1
- package/php/var/gettype.js +1 -1
- package/php/var/gettype.js.map +1 -1
- package/php/var/index.js +30 -30
- package/php/var/index.js.map +1 -1
- package/php/var/intval.js +2 -1
- package/php/var/intval.js.map +1 -1
- package/php/var/is_array.js.map +1 -1
- package/php/var/is_callable.js.map +1 -1
- package/php/var/is_double.js.map +1 -1
- package/php/var/is_integer.js.map +1 -1
- package/php/var/is_long.js.map +1 -1
- package/php/var/is_numeric.js.map +1 -1
- package/php/var/is_real.js.map +1 -1
- package/php/var/is_unicode.js.map +1 -1
- package/php/var/isset.js +1 -1
- package/php/var/isset.js.map +1 -1
- package/php/var/print_r.js.map +1 -1
- package/php/var/serialize.js +7 -5
- package/php/var/serialize.js.map +1 -1
- package/php/var/strval.js.map +1 -1
- package/php/var/unserialize.js +422 -236
- package/php/var/unserialize.js.map +1 -1
- package/php/var/var_dump.js +3 -3
- package/php/var/var_dump.js.map +1 -1
- package/php/var/var_export.js +5 -5
- package/php/var/var_export.js.map +1 -1
- package/php/xdiff/index.js +2 -2
- package/php/xdiff/index.js.map +1 -1
- package/php/xdiff/xdiff_string_diff.js +30 -30
- package/php/xdiff/xdiff_string_diff.js.map +1 -1
- package/php/xdiff/xdiff_string_patch.js +7 -8
- package/php/xdiff/xdiff_string_patch.js.map +1 -1
- package/php/xml/index.js +2 -2
- package/php/xml/index.js.map +1 -1
- package/php/xml/utf8_decode.js.map +1 -1
- package/php/xml/utf8_encode.js +2 -2
- package/php/xml/utf8_encode.js.map +1 -1
- package/python/index.js +1 -1
- package/python/index.js.map +1 -1
- package/python/string/capwords.js.map +1 -1
- package/python/string/index.js +4 -4
- package/python/string/index.js.map +1 -1
- package/python/string/punctuation.js +10 -0
- package/python/string/punctuation.js.map +1 -0
- package/ruby/Math/index.js +1 -1
- package/ruby/Math/index.js.map +1 -1
- package/ruby/index.js +1 -1
- package/ruby/index.js.map +1 -1
package/php/var/unserialize.js
CHANGED
|
@@ -1,252 +1,438 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// improved by: Le Torbi
|
|
12
|
-
// improved by: Eli Skeggs
|
|
13
|
-
// bugfixed by: dptr1988
|
|
14
|
-
// bugfixed by: Kevin van Zonneveld (https://kvz.io)
|
|
15
|
-
// bugfixed by: Brett Zamir (https://brett-zamir.me)
|
|
16
|
-
// bugfixed by: philippsimon (https://github.com/philippsimon/)
|
|
17
|
-
// revised by: d3x
|
|
18
|
-
// input by: Brett Zamir (https://brett-zamir.me)
|
|
19
|
-
// input by: Martin (https://www.erlenwiese.de/)
|
|
20
|
-
// input by: kilops
|
|
21
|
-
// input by: Jaroslaw Czarniak
|
|
22
|
-
// input by: lovasoa (https://github.com/lovasoa/)
|
|
23
|
-
// improved by: Rafał Kukawski
|
|
24
|
-
// note 1: We feel the main purpose of this function should be
|
|
25
|
-
// note 1: to ease the transport of data between php & js
|
|
26
|
-
// note 1: Aiming for PHP-compatibility, we have to translate objects to arrays
|
|
27
|
-
// example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}')
|
|
28
|
-
// returns 1: ['Kevin', 'van', 'Zonneveld']
|
|
29
|
-
// example 2: unserialize('a:2:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";}')
|
|
30
|
-
// returns 2: {firstName: 'Kevin', midName: 'van'}
|
|
31
|
-
// example 3: unserialize('a:3:{s:2:"ü";s:2:"ü";s:3:"四";s:3:"四";s:4:"𠜎";s:4:"𠜎";}')
|
|
32
|
-
// returns 3: {'ü': 'ü', '四': '四', '𠜎': '𠜎'}
|
|
33
|
-
// example 4: unserialize(undefined)
|
|
34
|
-
// returns 4: false
|
|
35
|
-
// example 5: unserialize('O:8:"stdClass":1:{s:3:"foo";b:1;}')
|
|
36
|
-
// returns 5: { foo: true }
|
|
37
|
-
|
|
38
|
-
var utf8Overhead = function utf8Overhead(str) {
|
|
39
|
-
var s = str.length;
|
|
40
|
-
for (var i = str.length - 1; i >= 0; i--) {
|
|
41
|
-
var code = str.charCodeAt(i);
|
|
42
|
-
if (code > 0x7f && code <= 0x7ff) {
|
|
43
|
-
s++;
|
|
44
|
-
} else if (code > 0x7ff && code <= 0xffff) {
|
|
45
|
-
s += 2;
|
|
46
|
-
}
|
|
47
|
-
// trail surrogate
|
|
48
|
-
if (code >= 0xDC00 && code <= 0xDFFF) {
|
|
49
|
-
i--;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return s - 1;
|
|
53
|
-
};
|
|
54
|
-
var readUntil = function readUntil(data, offset, stopchr) {
|
|
55
|
-
var i = 2;
|
|
56
|
-
var buf = [];
|
|
57
|
-
var chr = data.slice(offset, offset + 1);
|
|
58
|
-
|
|
59
|
-
while (chr !== stopchr) {
|
|
60
|
-
if (i + offset > data.length) {
|
|
61
|
-
throw Error('Invalid');
|
|
62
|
-
}
|
|
63
|
-
buf.push(chr);
|
|
64
|
-
chr = data.slice(offset + (i - 1), offset + i);
|
|
65
|
-
i += 1;
|
|
66
|
-
}
|
|
67
|
-
return [buf.length, buf.join('')];
|
|
3
|
+
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
4
|
+
|
|
5
|
+
function initCache() {
|
|
6
|
+
var store = [];
|
|
7
|
+
// cache only first element, second is length to jump ahead for the parser
|
|
8
|
+
var cache = function cache(value) {
|
|
9
|
+
store.push(value[0]);
|
|
10
|
+
return value;
|
|
68
11
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
for (i = 0; i < length; i++) {
|
|
74
|
-
chr = data.slice(offset + (i - 1), offset + i);
|
|
75
|
-
buf.push(chr);
|
|
76
|
-
length -= utf8Overhead(chr);
|
|
12
|
+
|
|
13
|
+
cache.get = function (index) {
|
|
14
|
+
if (index >= store.length) {
|
|
15
|
+
throw RangeError('Can\'t resolve reference ' + (index + 1));
|
|
77
16
|
}
|
|
78
|
-
|
|
17
|
+
|
|
18
|
+
return store[index];
|
|
79
19
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
20
|
+
|
|
21
|
+
return cache;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function expectType(str, cache) {
|
|
25
|
+
var types = /^(?:N(?=;)|[bidsSaOCrR](?=:)|[^:]+(?=:))/g;
|
|
26
|
+
var type = (types.exec(str) || [])[0];
|
|
27
|
+
|
|
28
|
+
if (!type) {
|
|
29
|
+
throw SyntaxError('Invalid input: ' + str);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
switch (type) {
|
|
33
|
+
case 'N':
|
|
34
|
+
return cache([null, 2]);
|
|
35
|
+
case 'b':
|
|
36
|
+
return cache(expectBool(str));
|
|
37
|
+
case 'i':
|
|
38
|
+
return cache(expectInt(str));
|
|
39
|
+
case 'd':
|
|
40
|
+
return cache(expectFloat(str));
|
|
41
|
+
case 's':
|
|
42
|
+
return cache(expectString(str));
|
|
43
|
+
case 'S':
|
|
44
|
+
return cache(expectEscapedString(str));
|
|
45
|
+
case 'a':
|
|
46
|
+
return expectArray(str, cache);
|
|
47
|
+
case 'O':
|
|
48
|
+
return expectObject(str, cache);
|
|
49
|
+
case 'C':
|
|
50
|
+
return expectClass(str, cache);
|
|
51
|
+
case 'r':
|
|
52
|
+
case 'R':
|
|
53
|
+
return expectReference(str, cache);
|
|
54
|
+
default:
|
|
55
|
+
throw SyntaxError('Invalid or unsupported data type: ' + type);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function expectBool(str) {
|
|
60
|
+
var reBool = /^b:([01]);/;
|
|
61
|
+
|
|
62
|
+
var _ref = reBool.exec(str) || [],
|
|
63
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
64
|
+
match = _ref2[0],
|
|
65
|
+
boolMatch = _ref2[1];
|
|
66
|
+
|
|
67
|
+
if (!boolMatch) {
|
|
68
|
+
throw SyntaxError('Invalid bool value, expected 0 or 1');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return [boolMatch === '1', match.length];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function expectInt(str) {
|
|
75
|
+
var reInt = /^i:([+-]?\d+);/;
|
|
76
|
+
|
|
77
|
+
var _ref3 = reInt.exec(str) || [],
|
|
78
|
+
_ref4 = _slicedToArray(_ref3, 2),
|
|
79
|
+
match = _ref4[0],
|
|
80
|
+
intMatch = _ref4[1];
|
|
81
|
+
|
|
82
|
+
if (!intMatch) {
|
|
83
|
+
throw SyntaxError('Expected an integer value');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return [parseInt(intMatch, 10), match.length];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function expectFloat(str) {
|
|
90
|
+
var reFloat = /^d:(NAN|-?INF|(?:\d+\.\d*|\d*\.\d+|\d+)(?:[eE][+-]\d+)?);/;
|
|
91
|
+
|
|
92
|
+
var _ref5 = reFloat.exec(str) || [],
|
|
93
|
+
_ref6 = _slicedToArray(_ref5, 2),
|
|
94
|
+
match = _ref6[0],
|
|
95
|
+
floatMatch = _ref6[1];
|
|
96
|
+
|
|
97
|
+
if (!floatMatch) {
|
|
98
|
+
throw SyntaxError('Expected a float value');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var floatValue = void 0;
|
|
102
|
+
|
|
103
|
+
switch (floatMatch) {
|
|
104
|
+
case 'NAN':
|
|
105
|
+
floatValue = Number.NaN;
|
|
106
|
+
break;
|
|
107
|
+
case '-INF':
|
|
108
|
+
floatValue = Number.NEGATIVE_INFINITY;
|
|
109
|
+
break;
|
|
110
|
+
case 'INF':
|
|
111
|
+
floatValue = Number.POSITIVE_INFINITY;
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
floatValue = parseFloat(floatMatch);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return [floatValue, match.length];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function readBytes(str, len) {
|
|
122
|
+
var escapedString = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
123
|
+
|
|
124
|
+
var bytes = 0;
|
|
125
|
+
var out = '';
|
|
126
|
+
var c = 0;
|
|
127
|
+
var strLen = str.length;
|
|
128
|
+
var wasHighSurrogate = false;
|
|
129
|
+
var escapedChars = 0;
|
|
130
|
+
|
|
131
|
+
while (bytes < len && c < strLen) {
|
|
132
|
+
var chr = str.charAt(c);
|
|
133
|
+
var code = chr.charCodeAt(0);
|
|
134
|
+
var isHighSurrogate = code >= 0xd800 && code <= 0xdbff;
|
|
135
|
+
var isLowSurrogate = code >= 0xdc00 && code <= 0xdfff;
|
|
136
|
+
|
|
137
|
+
if (escapedString && chr === '\\') {
|
|
138
|
+
chr = String.fromCharCode(parseInt(str.substr(c + 1, 2), 16));
|
|
139
|
+
escapedChars++;
|
|
140
|
+
|
|
141
|
+
// each escaped sequence is 3 characters. Go 2 chars ahead.
|
|
142
|
+
// third character will be jumped over a few lines later
|
|
143
|
+
c += 2;
|
|
107
144
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
145
|
+
|
|
146
|
+
c++;
|
|
147
|
+
|
|
148
|
+
bytes += isHighSurrogate || isLowSurrogate && wasHighSurrogate
|
|
149
|
+
// if high surrogate, count 2 bytes, as expectation is to be followed by low surrogate
|
|
150
|
+
// if low surrogate preceded by high surrogate, add 2 bytes
|
|
151
|
+
? 2 : code > 0x7ff
|
|
152
|
+
// otherwise low surrogate falls into this part
|
|
153
|
+
? 3 : code > 0x7f ? 2 : 1;
|
|
154
|
+
|
|
155
|
+
// if high surrogate is not followed by low surrogate, add 1 more byte
|
|
156
|
+
bytes += wasHighSurrogate && !isLowSurrogate ? 1 : 0;
|
|
157
|
+
|
|
158
|
+
out += chr;
|
|
159
|
+
wasHighSurrogate = isHighSurrogate;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return [out, bytes, escapedChars];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function expectString(str) {
|
|
166
|
+
// PHP strings consist of one-byte characters.
|
|
167
|
+
// JS uses 2 bytes with possible surrogate pairs.
|
|
168
|
+
// Serialized length of 2 is still 1 JS string character
|
|
169
|
+
var reStrLength = /^s:(\d+):"/g; // also match the opening " char
|
|
170
|
+
|
|
171
|
+
var _ref7 = reStrLength.exec(str) || [],
|
|
172
|
+
_ref8 = _slicedToArray(_ref7, 2),
|
|
173
|
+
match = _ref8[0],
|
|
174
|
+
byteLenMatch = _ref8[1];
|
|
175
|
+
|
|
176
|
+
if (!match) {
|
|
177
|
+
throw SyntaxError('Expected a string value');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
var len = parseInt(byteLenMatch, 10);
|
|
181
|
+
|
|
182
|
+
str = str.substr(match.length);
|
|
183
|
+
|
|
184
|
+
var _readBytes = readBytes(str, len),
|
|
185
|
+
_readBytes2 = _slicedToArray(_readBytes, 2),
|
|
186
|
+
strMatch = _readBytes2[0],
|
|
187
|
+
bytes = _readBytes2[1];
|
|
188
|
+
|
|
189
|
+
if (bytes !== len) {
|
|
190
|
+
throw SyntaxError('Expected string of ' + len + ' bytes, but got ' + bytes);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
str = str.substr(strMatch.length);
|
|
194
|
+
|
|
195
|
+
// strict parsing, match closing "; chars
|
|
196
|
+
if (!str.startsWith('";')) {
|
|
197
|
+
throw SyntaxError('Expected ";');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return [strMatch, match.length + strMatch.length + 2]; // skip last ";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function expectEscapedString(str) {
|
|
204
|
+
var reStrLength = /^S:(\d+):"/g; // also match the opening " char
|
|
205
|
+
|
|
206
|
+
var _ref9 = reStrLength.exec(str) || [],
|
|
207
|
+
_ref10 = _slicedToArray(_ref9, 2),
|
|
208
|
+
match = _ref10[0],
|
|
209
|
+
strLenMatch = _ref10[1];
|
|
210
|
+
|
|
211
|
+
if (!match) {
|
|
212
|
+
throw SyntaxError('Expected an escaped string value');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var len = parseInt(strLenMatch, 10);
|
|
216
|
+
|
|
217
|
+
str = str.substr(match.length);
|
|
218
|
+
|
|
219
|
+
var _readBytes3 = readBytes(str, len, true),
|
|
220
|
+
_readBytes4 = _slicedToArray(_readBytes3, 3),
|
|
221
|
+
strMatch = _readBytes4[0],
|
|
222
|
+
bytes = _readBytes4[1],
|
|
223
|
+
escapedChars = _readBytes4[2];
|
|
224
|
+
|
|
225
|
+
if (bytes !== len) {
|
|
226
|
+
throw SyntaxError('Expected escaped string of ' + len + ' bytes, but got ' + bytes);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
str = str.substr(strMatch.length + escapedChars * 2);
|
|
230
|
+
|
|
231
|
+
// strict parsing, match closing "; chars
|
|
232
|
+
if (!str.startsWith('";')) {
|
|
233
|
+
throw SyntaxError('Expected ";');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return [strMatch, match.length + strMatch.length + 2]; // skip last ";
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function expectKeyOrIndex(str) {
|
|
240
|
+
try {
|
|
241
|
+
return expectString(str);
|
|
242
|
+
} catch (err) {}
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
return expectEscapedString(str);
|
|
246
|
+
} catch (err) {}
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
return expectInt(str);
|
|
250
|
+
} catch (err) {
|
|
251
|
+
throw SyntaxError('Expected key or index');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function expectObject(str, cache) {
|
|
256
|
+
// O:<class name length>:"class name":<prop count>:{<props and values>}
|
|
257
|
+
// O:8:"stdClass":2:{s:3:"foo";s:3:"bar";s:3:"bar";s:3:"baz";}
|
|
258
|
+
var reObjectLiteral = /^O:(\d+):"([^"]+)":(\d+):\{/;
|
|
259
|
+
|
|
260
|
+
var _ref11 = reObjectLiteral.exec(str) || [],
|
|
261
|
+
_ref12 = _slicedToArray(_ref11, 4),
|
|
262
|
+
objectLiteralBeginMatch = _ref12[0],
|
|
263
|
+
/* classNameLengthMatch */className = _ref12[2],
|
|
264
|
+
propCountMatch = _ref12[3];
|
|
265
|
+
|
|
266
|
+
if (!objectLiteralBeginMatch) {
|
|
267
|
+
throw SyntaxError('Invalid input');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (className !== 'stdClass') {
|
|
271
|
+
throw SyntaxError('Unsupported object type: ' + className);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var totalOffset = objectLiteralBeginMatch.length;
|
|
275
|
+
|
|
276
|
+
var propCount = parseInt(propCountMatch, 10);
|
|
277
|
+
var obj = {};
|
|
278
|
+
cache([obj]);
|
|
279
|
+
|
|
280
|
+
str = str.substr(totalOffset);
|
|
281
|
+
|
|
282
|
+
for (var i = 0; i < propCount; i++) {
|
|
283
|
+
var prop = expectKeyOrIndex(str);
|
|
284
|
+
str = str.substr(prop[1]);
|
|
285
|
+
totalOffset += prop[1];
|
|
286
|
+
|
|
287
|
+
var value = expectType(str, cache);
|
|
288
|
+
str = str.substr(value[1]);
|
|
289
|
+
totalOffset += value[1];
|
|
290
|
+
|
|
291
|
+
obj[prop[0]] = value[0];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// strict parsing, expect } after object literal
|
|
295
|
+
if (str.charAt(0) !== '}') {
|
|
296
|
+
throw SyntaxError('Expected }');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return [obj, totalOffset + 1]; // skip final }
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function expectClass(str, cache) {
|
|
303
|
+
// can't be well supported, because requires calling eval (or similar)
|
|
304
|
+
// in order to call serialized constructor name
|
|
305
|
+
// which is unsafe
|
|
306
|
+
// or assume that constructor is defined in global scope
|
|
307
|
+
// but this is too much limiting
|
|
308
|
+
throw Error('Not yet implemented');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function expectReference(str, cache) {
|
|
312
|
+
var reRef = /^[rR]:([1-9]\d*);/;
|
|
313
|
+
|
|
314
|
+
var _ref13 = reRef.exec(str) || [],
|
|
315
|
+
_ref14 = _slicedToArray(_ref13, 2),
|
|
316
|
+
match = _ref14[0],
|
|
317
|
+
refIndex = _ref14[1];
|
|
318
|
+
|
|
319
|
+
if (!match) {
|
|
320
|
+
throw SyntaxError('Expected reference value');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return [cache.get(parseInt(refIndex, 10) - 1), match.length];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function expectArray(str, cache) {
|
|
327
|
+
var reArrayLength = /^a:(\d+):{/;
|
|
328
|
+
|
|
329
|
+
var _ref15 = reArrayLength.exec(str) || [],
|
|
330
|
+
_ref16 = _slicedToArray(_ref15, 2),
|
|
331
|
+
arrayLiteralBeginMatch = _ref16[0],
|
|
332
|
+
arrayLengthMatch = _ref16[1];
|
|
333
|
+
|
|
334
|
+
if (!arrayLengthMatch) {
|
|
335
|
+
throw SyntaxError('Expected array length annotation');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
str = str.substr(arrayLiteralBeginMatch.length);
|
|
339
|
+
|
|
340
|
+
var array = expectArrayItems(str, parseInt(arrayLengthMatch, 10), cache);
|
|
341
|
+
|
|
342
|
+
// strict parsing, expect closing } brace after array literal
|
|
343
|
+
if (str.charAt(array[1]) !== '}') {
|
|
344
|
+
throw SyntaxError('Expected }');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return [array[0], arrayLiteralBeginMatch.length + array[1] + 1]; // jump over }
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function expectArrayItems(str) {
|
|
351
|
+
var expectedItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
352
|
+
var cache = arguments[2];
|
|
353
|
+
|
|
354
|
+
var key = void 0;
|
|
355
|
+
var hasStringKeys = false;
|
|
356
|
+
var item = void 0;
|
|
357
|
+
var totalOffset = 0;
|
|
358
|
+
var items = [];
|
|
359
|
+
cache([items]);
|
|
360
|
+
|
|
361
|
+
for (var i = 0; i < expectedItems; i++) {
|
|
362
|
+
key = expectKeyOrIndex(str);
|
|
363
|
+
|
|
364
|
+
// this is for backward compatibility with previous implementation
|
|
365
|
+
if (!hasStringKeys) {
|
|
366
|
+
hasStringKeys = typeof key[0] === 'string';
|
|
240
367
|
}
|
|
241
|
-
|
|
368
|
+
|
|
369
|
+
str = str.substr(key[1]);
|
|
370
|
+
totalOffset += key[1];
|
|
371
|
+
|
|
372
|
+
// references are resolved immediately, so if duplicate key overwrites previous array index
|
|
373
|
+
// the old value is anyway resolved
|
|
374
|
+
// fixme: but next time the same reference should point to the new value
|
|
375
|
+
item = expectType(str, cache);
|
|
376
|
+
str = str.substr(item[1]);
|
|
377
|
+
totalOffset += item[1];
|
|
378
|
+
|
|
379
|
+
items[key[0]] = item[0];
|
|
242
380
|
}
|
|
243
381
|
|
|
382
|
+
// this is for backward compatibility with previous implementation
|
|
383
|
+
if (hasStringKeys) {
|
|
384
|
+
items = Object.assign({}, items);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return [items, totalOffset];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
module.exports = function unserialize(str) {
|
|
391
|
+
// discuss at: https://locutus.io/php/unserialize/
|
|
392
|
+
// original by: Arpad Ray (mailto:arpad@php.net)
|
|
393
|
+
// improved by: Pedro Tainha (https://www.pedrotainha.com)
|
|
394
|
+
// improved by: Kevin van Zonneveld (https://kvz.io)
|
|
395
|
+
// improved by: Kevin van Zonneveld (https://kvz.io)
|
|
396
|
+
// improved by: Chris
|
|
397
|
+
// improved by: James
|
|
398
|
+
// improved by: Le Torbi
|
|
399
|
+
// improved by: Eli Skeggs
|
|
400
|
+
// bugfixed by: dptr1988
|
|
401
|
+
// bugfixed by: Kevin van Zonneveld (https://kvz.io)
|
|
402
|
+
// bugfixed by: Brett Zamir (https://brett-zamir.me)
|
|
403
|
+
// bugfixed by: philippsimon (https://github.com/philippsimon/)
|
|
404
|
+
// revised by: d3x
|
|
405
|
+
// input by: Brett Zamir (https://brett-zamir.me)
|
|
406
|
+
// input by: Martin (https://www.erlenwiese.de/)
|
|
407
|
+
// input by: kilops
|
|
408
|
+
// input by: Jaroslaw Czarniak
|
|
409
|
+
// input by: lovasoa (https://github.com/lovasoa/)
|
|
410
|
+
// improved by: Rafał Kukawski
|
|
411
|
+
// reimplemented by: Rafał Kukawski
|
|
412
|
+
// note 1: We feel the main purpose of this function should be
|
|
413
|
+
// note 1: to ease the transport of data between php & js
|
|
414
|
+
// note 1: Aiming for PHP-compatibility, we have to translate objects to arrays
|
|
415
|
+
// example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}')
|
|
416
|
+
// returns 1: ['Kevin', 'van', 'Zonneveld']
|
|
417
|
+
// example 2: unserialize('a:2:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";}')
|
|
418
|
+
// returns 2: {firstName: 'Kevin', midName: 'van'}
|
|
419
|
+
// example 3: unserialize('a:3:{s:2:"ü";s:2:"ü";s:3:"四";s:3:"四";s:4:"𠜎";s:4:"𠜎";}')
|
|
420
|
+
// returns 3: {'ü': 'ü', '四': '四', '𠜎': '𠜎'}
|
|
421
|
+
// example 4: unserialize(undefined)
|
|
422
|
+
// returns 4: false
|
|
423
|
+
// example 5: unserialize('O:8:"stdClass":1:{s:3:"foo";b:1;}')
|
|
424
|
+
// returns 5: { foo: true }
|
|
425
|
+
// example 6: unserialize('a:2:{i:0;N;i:1;s:0:"";}')
|
|
426
|
+
// returns 6: [null, ""]
|
|
427
|
+
// example 7: unserialize('S:7:"\\65\\73\\63\\61\\70\\65\\64";')
|
|
428
|
+
// returns 7: 'escaped'
|
|
429
|
+
|
|
244
430
|
try {
|
|
245
|
-
if (typeof
|
|
431
|
+
if (typeof str !== 'string') {
|
|
246
432
|
return false;
|
|
247
433
|
}
|
|
248
434
|
|
|
249
|
-
return
|
|
435
|
+
return expectType(str, initCache())[0];
|
|
250
436
|
} catch (err) {
|
|
251
437
|
console.error(err);
|
|
252
438
|
return false;
|