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.
Files changed (419) hide show
  1. package/_util/cli.js.map +1 -1
  2. package/_util/util.js +11 -16
  3. package/_util/util.js.map +1 -1
  4. package/c/index.js +2 -2
  5. package/c/index.js.map +1 -1
  6. package/c/math/index.js +2 -2
  7. package/c/math/index.js.map +1 -1
  8. package/c/stdio/index.js +1 -1
  9. package/c/stdio/index.js.map +1 -1
  10. package/c/stdio/sprintf.js +8 -1
  11. package/c/stdio/sprintf.js.map +1 -1
  12. package/golang/index.js +1 -1
  13. package/golang/index.js.map +1 -1
  14. package/golang/strings/Count.js +1 -1
  15. package/golang/strings/Count.js.map +1 -1
  16. package/golang/strings/index.js +4 -4
  17. package/golang/strings/index.js.map +1 -1
  18. package/index.js +5 -5
  19. package/index.js.map +1 -1
  20. package/package.json +39 -40
  21. package/php/_helpers/_bc.js +104 -48
  22. package/php/_helpers/_bc.js.map +1 -1
  23. package/php/_helpers/_phpCastString.js.map +1 -1
  24. package/php/_helpers/_php_cast_float.js.map +1 -1
  25. package/php/_helpers/_php_cast_int.js.map +1 -1
  26. package/php/_helpers/index.js +4 -4
  27. package/php/_helpers/index.js.map +1 -1
  28. package/php/array/array_change_key_case.js +2 -2
  29. package/php/array/array_change_key_case.js.map +1 -1
  30. package/php/array/array_chunk.js +1 -1
  31. package/php/array/array_chunk.js.map +1 -1
  32. package/php/array/array_column.js.map +1 -1
  33. package/php/array/array_combine.js.map +1 -1
  34. package/php/array/array_count_values.js.map +1 -1
  35. package/php/array/array_diff.js.map +1 -1
  36. package/php/array/array_diff_assoc.js.map +1 -1
  37. package/php/array/array_diff_key.js.map +1 -1
  38. package/php/array/array_diff_uassoc.js.map +1 -1
  39. package/php/array/array_diff_ukey.js.map +1 -1
  40. package/php/array/array_fill.js +1 -1
  41. package/php/array/array_fill.js.map +1 -1
  42. package/php/array/array_fill_keys.js.map +1 -1
  43. package/php/array/array_filter.js +1 -1
  44. package/php/array/array_filter.js.map +1 -1
  45. package/php/array/array_flip.js +1 -1
  46. package/php/array/array_flip.js.map +1 -1
  47. package/php/array/array_intersect.js.map +1 -1
  48. package/php/array/array_intersect_assoc.js.map +1 -1
  49. package/php/array/array_intersect_key.js.map +1 -1
  50. package/php/array/array_intersect_uassoc.js.map +1 -1
  51. package/php/array/array_intersect_ukey.js.map +1 -1
  52. package/php/array/array_keys.js.map +1 -1
  53. package/php/array/array_map.js.map +1 -1
  54. package/php/array/array_merge.js +1 -1
  55. package/php/array/array_merge.js.map +1 -1
  56. package/php/array/array_merge_recursive.js.map +1 -1
  57. package/php/array/array_multisort.js +16 -16
  58. package/php/array/array_multisort.js.map +1 -1
  59. package/php/array/array_pad.js +1 -1
  60. package/php/array/array_pad.js.map +1 -1
  61. package/php/array/array_pop.js.map +1 -1
  62. package/php/array/array_product.js.map +1 -1
  63. package/php/array/array_push.js.map +1 -1
  64. package/php/array/array_rand.js.map +1 -1
  65. package/php/array/array_reduce.js.map +1 -1
  66. package/php/array/array_replace.js.map +1 -1
  67. package/php/array/array_replace_recursive.js +1 -1
  68. package/php/array/array_replace_recursive.js.map +1 -1
  69. package/php/array/array_reverse.js +1 -1
  70. package/php/array/array_reverse.js.map +1 -1
  71. package/php/array/array_search.js.map +1 -1
  72. package/php/array/array_shift.js +0 -19
  73. package/php/array/array_shift.js.map +1 -1
  74. package/php/array/array_slice.js.map +1 -1
  75. package/php/array/array_splice.js.map +1 -1
  76. package/php/array/array_sum.js +1 -1
  77. package/php/array/array_sum.js.map +1 -1
  78. package/php/array/array_udiff.js.map +1 -1
  79. package/php/array/array_udiff_assoc.js.map +1 -1
  80. package/php/array/array_udiff_uassoc.js.map +1 -1
  81. package/php/array/array_uintersect.js.map +1 -1
  82. package/php/array/array_uintersect_uassoc.js.map +1 -1
  83. package/php/array/array_unique.js.map +1 -1
  84. package/php/array/array_unshift.js.map +1 -1
  85. package/php/array/array_values.js.map +1 -1
  86. package/php/array/array_walk.js.map +1 -1
  87. package/php/array/array_walk_recursive.js.map +1 -1
  88. package/php/array/arsort.js +3 -3
  89. package/php/array/arsort.js.map +1 -1
  90. package/php/array/asort.js +3 -3
  91. package/php/array/asort.js.map +1 -1
  92. package/php/array/count.js +1 -1
  93. package/php/array/count.js.map +1 -1
  94. package/php/array/current.js.map +1 -1
  95. package/php/array/each.js.map +1 -1
  96. package/php/array/end.js +1 -1
  97. package/php/array/end.js.map +1 -1
  98. package/php/array/in_array.js.map +1 -1
  99. package/php/array/index.js +73 -72
  100. package/php/array/index.js.map +1 -1
  101. package/php/array/key.js.map +1 -1
  102. package/php/array/krsort.js +3 -3
  103. package/php/array/krsort.js.map +1 -1
  104. package/php/array/ksort.js +3 -3
  105. package/php/array/ksort.js.map +1 -1
  106. package/php/array/natcasesort.js +2 -2
  107. package/php/array/natcasesort.js.map +1 -1
  108. package/php/array/natsort.js +2 -2
  109. package/php/array/natsort.js.map +1 -1
  110. package/php/array/next.js.map +1 -1
  111. package/php/array/pos.js.map +1 -1
  112. package/php/array/prev.js.map +1 -1
  113. package/php/array/range.js +3 -3
  114. package/php/array/range.js.map +1 -1
  115. package/php/array/reset.js.map +1 -1
  116. package/php/array/rsort.js +3 -3
  117. package/php/array/rsort.js.map +1 -1
  118. package/php/array/shuffle.js.map +1 -1
  119. package/php/array/sizeof.js.map +1 -1
  120. package/php/array/sort.js +3 -3
  121. package/php/array/sort.js.map +1 -1
  122. package/php/array/uasort.js.map +1 -1
  123. package/php/array/uksort.js.map +1 -1
  124. package/php/array/usort.js.map +1 -1
  125. package/php/bc/bcadd.js +3 -1
  126. package/php/bc/bcadd.js.map +1 -1
  127. package/php/bc/bccomp.js +2 -1
  128. package/php/bc/bccomp.js.map +1 -1
  129. package/php/bc/bcdiv.js +3 -1
  130. package/php/bc/bcdiv.js.map +1 -1
  131. package/php/bc/bcmul.js +3 -1
  132. package/php/bc/bcmul.js.map +1 -1
  133. package/php/bc/bcround.js +4 -2
  134. package/php/bc/bcround.js.map +1 -1
  135. package/php/bc/bcscale.js.map +1 -1
  136. package/php/bc/bcsub.js +3 -1
  137. package/php/bc/bcsub.js.map +1 -1
  138. package/php/bc/index.js +7 -7
  139. package/php/bc/index.js.map +1 -1
  140. package/php/ctype/ctype_alnum.js.map +1 -1
  141. package/php/ctype/ctype_alpha.js.map +1 -1
  142. package/php/ctype/ctype_cntrl.js.map +1 -1
  143. package/php/ctype/ctype_digit.js.map +1 -1
  144. package/php/ctype/ctype_graph.js.map +1 -1
  145. package/php/ctype/ctype_lower.js.map +1 -1
  146. package/php/ctype/ctype_print.js.map +1 -1
  147. package/php/ctype/ctype_punct.js.map +1 -1
  148. package/php/ctype/ctype_space.js.map +1 -1
  149. package/php/ctype/ctype_upper.js.map +1 -1
  150. package/php/ctype/ctype_xdigit.js.map +1 -1
  151. package/php/ctype/index.js +11 -11
  152. package/php/ctype/index.js.map +1 -1
  153. package/php/datetime/date.js +2 -1
  154. package/php/datetime/date.js.map +1 -1
  155. package/php/datetime/date_parse.js +1 -1
  156. package/php/datetime/date_parse.js.map +1 -1
  157. package/php/datetime/getdate.js.map +1 -1
  158. package/php/datetime/gettimeofday.js.map +1 -1
  159. package/php/datetime/gmdate.js.map +1 -1
  160. package/php/datetime/gmmktime.js.map +1 -1
  161. package/php/datetime/gmstrftime.js.map +1 -1
  162. package/php/datetime/idate.js +1 -1
  163. package/php/datetime/idate.js.map +1 -1
  164. package/php/datetime/index.js +15 -15
  165. package/php/datetime/index.js.map +1 -1
  166. package/php/datetime/microtime.js +3 -3
  167. package/php/datetime/microtime.js.map +1 -1
  168. package/php/datetime/mktime.js.map +1 -1
  169. package/php/datetime/strftime.js +2 -3
  170. package/php/datetime/strftime.js.map +1 -1
  171. package/php/datetime/strptime.js +20 -21
  172. package/php/datetime/strptime.js.map +1 -1
  173. package/php/datetime/strtotime.js +170 -4
  174. package/php/datetime/strtotime.js.map +1 -1
  175. package/php/exec/escapeshellarg.js +12 -4
  176. package/php/exec/escapeshellarg.js.map +1 -1
  177. package/php/exec/index.js +1 -1
  178. package/php/exec/index.js.map +1 -1
  179. package/php/filesystem/basename.js.map +1 -1
  180. package/php/filesystem/file_get_contents.js.map +1 -1
  181. package/php/filesystem/index.js +5 -5
  182. package/php/filesystem/index.js.map +1 -1
  183. package/php/filesystem/pathinfo.js +7 -8
  184. package/php/filesystem/pathinfo.js.map +1 -1
  185. package/php/filesystem/realpath.js.map +1 -1
  186. package/php/funchand/call_user_func.js.map +1 -1
  187. package/php/funchand/call_user_func_array.js +1 -1
  188. package/php/funchand/call_user_func_array.js.map +1 -1
  189. package/php/funchand/function_exists.js.map +1 -1
  190. package/php/funchand/get_defined_functions.js.map +1 -1
  191. package/php/funchand/index.js +5 -5
  192. package/php/funchand/index.js.map +1 -1
  193. package/php/i18n/i18n_loc_get_default.js.map +1 -1
  194. package/php/i18n/i18n_loc_set_default.js.map +1 -1
  195. package/php/i18n/index.js +2 -2
  196. package/php/i18n/index.js.map +1 -1
  197. package/php/index.js +19 -19
  198. package/php/index.js.map +1 -1
  199. package/php/info/assert_options.js +2 -1
  200. package/php/info/assert_options.js.map +1 -1
  201. package/php/info/index.js +6 -6
  202. package/php/info/index.js.map +1 -1
  203. package/php/info/ini_get.js.map +1 -1
  204. package/php/info/ini_set.js.map +1 -1
  205. package/php/info/set_time_limit.js.map +1 -1
  206. package/php/info/version_compare.js +21 -22
  207. package/php/info/version_compare.js.map +1 -1
  208. package/php/json/index.js +3 -3
  209. package/php/json/index.js.map +1 -1
  210. package/php/json/json_decode.js +1 -1
  211. package/php/json/json_decode.js.map +1 -1
  212. package/php/json/json_encode.js +1 -1
  213. package/php/json/json_encode.js.map +1 -1
  214. package/php/json/json_last_error.js.map +1 -1
  215. package/php/math/fmod.js +2 -2
  216. package/php/math/fmod.js.map +1 -1
  217. package/php/math/hypot.js.map +1 -1
  218. package/php/math/index.js +46 -46
  219. package/php/math/index.js.map +1 -1
  220. package/php/math/is_finite.js.map +1 -1
  221. package/php/math/is_infinite.js.map +1 -1
  222. package/php/math/is_nan.js.map +1 -1
  223. package/php/math/log1p.js.map +1 -1
  224. package/php/math/max.js +7 -7
  225. package/php/math/max.js.map +1 -1
  226. package/php/math/min.js +5 -5
  227. package/php/math/min.js.map +1 -1
  228. package/php/math/mt_rand.js.map +1 -1
  229. package/php/math/rand.js.map +1 -1
  230. package/php/math/round.js +1 -1
  231. package/php/math/round.js.map +1 -1
  232. package/php/misc/index.js +2 -2
  233. package/php/misc/index.js.map +1 -1
  234. package/php/misc/pack.js +23 -18
  235. package/php/misc/pack.js.map +1 -1
  236. package/php/misc/uniqid.js +1 -1
  237. package/php/misc/uniqid.js.map +1 -1
  238. package/php/net-gopher/gopher_parsedir.js +3 -4
  239. package/php/net-gopher/gopher_parsedir.js.map +1 -1
  240. package/php/net-gopher/index.js +1 -1
  241. package/php/net-gopher/index.js.map +1 -1
  242. package/php/network/index.js +6 -6
  243. package/php/network/index.js.map +1 -1
  244. package/php/network/inet_ntop.js.map +1 -1
  245. package/php/network/inet_pton.js +40 -32
  246. package/php/network/inet_pton.js.map +1 -1
  247. package/php/network/setcookie.js.map +1 -1
  248. package/php/network/setrawcookie.js.map +1 -1
  249. package/php/pcre/index.js +4 -3
  250. package/php/pcre/index.js.map +1 -1
  251. package/php/pcre/preg_replace.js +24 -0
  252. package/php/pcre/preg_replace.js.map +1 -0
  253. package/php/pcre/sql_regcase.js.map +1 -1
  254. package/php/strings/addcslashes.js.map +1 -1
  255. package/php/strings/bin2hex.js +3 -3
  256. package/php/strings/bin2hex.js.map +1 -1
  257. package/php/strings/chop.js.map +1 -1
  258. package/php/strings/convert_cyr_string.js +1 -1
  259. package/php/strings/convert_cyr_string.js.map +1 -1
  260. package/php/strings/convert_uuencode.js.map +1 -1
  261. package/php/strings/count_chars.js +1 -1
  262. package/php/strings/count_chars.js.map +1 -1
  263. package/php/strings/crc32.js.map +1 -1
  264. package/php/strings/echo.js.map +1 -1
  265. package/php/strings/explode.js.map +1 -1
  266. package/php/strings/get_html_translation_table.js +1 -1
  267. package/php/strings/get_html_translation_table.js.map +1 -1
  268. package/php/strings/hex2bin.js +1 -1
  269. package/php/strings/hex2bin.js.map +1 -1
  270. package/php/strings/html_entity_decode.js.map +1 -1
  271. package/php/strings/htmlentities.js.map +1 -1
  272. package/php/strings/htmlspecialchars.js +6 -6
  273. package/php/strings/htmlspecialchars.js.map +1 -1
  274. package/php/strings/htmlspecialchars_decode.js +6 -6
  275. package/php/strings/htmlspecialchars_decode.js.map +1 -1
  276. package/php/strings/implode.js.map +1 -1
  277. package/php/strings/index.js +91 -91
  278. package/php/strings/index.js.map +1 -1
  279. package/php/strings/join.js.map +1 -1
  280. package/php/strings/lcfirst.js.map +1 -1
  281. package/php/strings/levenshtein.js +6 -1
  282. package/php/strings/levenshtein.js.map +1 -1
  283. package/php/strings/localeconv.js.map +1 -1
  284. package/php/strings/ltrim.js.map +1 -1
  285. package/php/strings/md5.js +19 -15
  286. package/php/strings/md5.js.map +1 -1
  287. package/php/strings/md5_file.js.map +1 -1
  288. package/php/strings/metaphone.js +2 -2
  289. package/php/strings/metaphone.js.map +1 -1
  290. package/php/strings/money_format.js.map +1 -1
  291. package/php/strings/nl2br.js.map +1 -1
  292. package/php/strings/nl_langinfo.js.map +1 -1
  293. package/php/strings/number_format.js.map +1 -1
  294. package/php/strings/ord.js.map +1 -1
  295. package/php/strings/parse_str.js +13 -13
  296. package/php/strings/parse_str.js.map +1 -1
  297. package/php/strings/printf.js.map +1 -1
  298. package/php/strings/quoted_printable_decode.js.map +1 -1
  299. package/php/strings/quoted_printable_encode.js.map +1 -1
  300. package/php/strings/rtrim.js.map +1 -1
  301. package/php/strings/setlocale.js +18 -19
  302. package/php/strings/setlocale.js.map +1 -1
  303. package/php/strings/sha1.js +12 -7
  304. package/php/strings/sha1.js.map +1 -1
  305. package/php/strings/sha1_file.js.map +1 -1
  306. package/php/strings/similar_text.js +4 -4
  307. package/php/strings/similar_text.js.map +1 -1
  308. package/php/strings/soundex.js +3 -3
  309. package/php/strings/soundex.js.map +1 -1
  310. package/php/strings/split.js.map +1 -1
  311. package/php/strings/sprintf.js +7 -2
  312. package/php/strings/sprintf.js.map +1 -1
  313. package/php/strings/sscanf.js +2 -2
  314. package/php/strings/sscanf.js.map +1 -1
  315. package/php/strings/str_getcsv.js +2 -2
  316. package/php/strings/str_getcsv.js.map +1 -1
  317. package/php/strings/str_ireplace.js +6 -0
  318. package/php/strings/str_ireplace.js.map +1 -1
  319. package/php/strings/str_pad.js +1 -1
  320. package/php/strings/str_pad.js.map +1 -1
  321. package/php/strings/str_repeat.js.map +1 -1
  322. package/php/strings/str_replace.js +6 -0
  323. package/php/strings/str_replace.js.map +1 -1
  324. package/php/strings/str_shuffle.js +1 -1
  325. package/php/strings/str_shuffle.js.map +1 -1
  326. package/php/strings/str_split.js.map +1 -1
  327. package/php/strings/str_word_count.js.map +1 -1
  328. package/php/strings/strcasecmp.js.map +1 -1
  329. package/php/strings/strchr.js.map +1 -1
  330. package/php/strings/strcoll.js.map +1 -1
  331. package/php/strings/strip_tags.js.map +1 -1
  332. package/php/strings/stripos.js.map +1 -1
  333. package/php/strings/stristr.js.map +1 -1
  334. package/php/strings/strlen.js.map +1 -1
  335. package/php/strings/strnatcasecmp.js.map +1 -1
  336. package/php/strings/strnatcmp.js.map +1 -1
  337. package/php/strings/strncasecmp.js +1 -1
  338. package/php/strings/strncasecmp.js.map +1 -1
  339. package/php/strings/strncmp.js.map +1 -1
  340. package/php/strings/strpbrk.js.map +1 -1
  341. package/php/strings/strpos.js.map +1 -1
  342. package/php/strings/strrchr.js.map +1 -1
  343. package/php/strings/strrev.js.map +1 -1
  344. package/php/strings/strripos.js.map +1 -1
  345. package/php/strings/strrpos.js.map +1 -1
  346. package/php/strings/strspn.js +3 -3
  347. package/php/strings/strspn.js.map +1 -1
  348. package/php/strings/strstr.js.map +1 -1
  349. package/php/strings/strtok.js.map +1 -1
  350. package/php/strings/strtr.js.map +1 -1
  351. package/php/strings/substr.js.map +1 -1
  352. package/php/strings/substr_count.js.map +1 -1
  353. package/php/strings/trim.js.map +1 -1
  354. package/php/strings/ucfirst.js.map +1 -1
  355. package/php/strings/vprintf.js.map +1 -1
  356. package/php/strings/vsprintf.js.map +1 -1
  357. package/php/strings/wordwrap.js +4 -2
  358. package/php/strings/wordwrap.js.map +1 -1
  359. package/php/url/base64_decode.js +8 -8
  360. package/php/url/base64_decode.js.map +1 -1
  361. package/php/url/base64_encode.js +8 -8
  362. package/php/url/base64_encode.js.map +1 -1
  363. package/php/url/http_build_query.js +4 -4
  364. package/php/url/http_build_query.js.map +1 -1
  365. package/php/url/index.js +8 -8
  366. package/php/url/index.js.map +1 -1
  367. package/php/url/parse_url.js +1 -1
  368. package/php/url/parse_url.js.map +1 -1
  369. package/php/var/doubleval.js.map +1 -1
  370. package/php/var/empty.js +4 -4
  371. package/php/var/empty.js.map +1 -1
  372. package/php/var/gettype.js +1 -1
  373. package/php/var/gettype.js.map +1 -1
  374. package/php/var/index.js +30 -30
  375. package/php/var/index.js.map +1 -1
  376. package/php/var/intval.js +2 -1
  377. package/php/var/intval.js.map +1 -1
  378. package/php/var/is_array.js.map +1 -1
  379. package/php/var/is_callable.js.map +1 -1
  380. package/php/var/is_double.js.map +1 -1
  381. package/php/var/is_integer.js.map +1 -1
  382. package/php/var/is_long.js.map +1 -1
  383. package/php/var/is_numeric.js.map +1 -1
  384. package/php/var/is_real.js.map +1 -1
  385. package/php/var/is_unicode.js.map +1 -1
  386. package/php/var/isset.js +1 -1
  387. package/php/var/isset.js.map +1 -1
  388. package/php/var/print_r.js.map +1 -1
  389. package/php/var/serialize.js +7 -5
  390. package/php/var/serialize.js.map +1 -1
  391. package/php/var/strval.js.map +1 -1
  392. package/php/var/unserialize.js +422 -236
  393. package/php/var/unserialize.js.map +1 -1
  394. package/php/var/var_dump.js +3 -3
  395. package/php/var/var_dump.js.map +1 -1
  396. package/php/var/var_export.js +5 -5
  397. package/php/var/var_export.js.map +1 -1
  398. package/php/xdiff/index.js +2 -2
  399. package/php/xdiff/index.js.map +1 -1
  400. package/php/xdiff/xdiff_string_diff.js +30 -30
  401. package/php/xdiff/xdiff_string_diff.js.map +1 -1
  402. package/php/xdiff/xdiff_string_patch.js +7 -8
  403. package/php/xdiff/xdiff_string_patch.js.map +1 -1
  404. package/php/xml/index.js +2 -2
  405. package/php/xml/index.js.map +1 -1
  406. package/php/xml/utf8_decode.js.map +1 -1
  407. package/php/xml/utf8_encode.js +2 -2
  408. package/php/xml/utf8_encode.js.map +1 -1
  409. package/python/index.js +1 -1
  410. package/python/index.js.map +1 -1
  411. package/python/string/capwords.js.map +1 -1
  412. package/python/string/index.js +4 -4
  413. package/python/string/index.js.map +1 -1
  414. package/python/string/punctuation.js +10 -0
  415. package/python/string/punctuation.js.map +1 -0
  416. package/ruby/Math/index.js +1 -1
  417. package/ruby/Math/index.js.map +1 -1
  418. package/ruby/index.js +1 -1
  419. package/ruby/index.js.map +1 -1
@@ -1,252 +1,438 @@
1
1
  'use strict';
2
2
 
3
- module.exports = function unserialize(data) {
4
- // discuss at: https://locutus.io/php/unserialize/
5
- // original by: Arpad Ray (mailto:arpad@php.net)
6
- // improved by: Pedro Tainha (https://www.pedrotainha.com)
7
- // improved by: Kevin van Zonneveld (https://kvz.io)
8
- // improved by: Kevin van Zonneveld (https://kvz.io)
9
- // improved by: Chris
10
- // improved by: James
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
- var readChrs = function readChrs(data, offset, length) {
70
- var i, chr, buf;
71
-
72
- buf = [];
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
- return [buf.length, buf.join('')];
17
+
18
+ return store[index];
79
19
  };
80
- function _unserialize(data, offset) {
81
- var dtype;
82
- var dataoffset;
83
- var keyandchrs;
84
- var keys;
85
- var contig;
86
- var length;
87
- var array;
88
- var obj;
89
- var readdata;
90
- var readData;
91
- var ccount;
92
- var stringlength;
93
- var i;
94
- var key;
95
- var kprops;
96
- var kchrs;
97
- var vprops;
98
- var vchrs;
99
- var value;
100
- var chrs = 0;
101
- var typeconvert = function typeconvert(x) {
102
- return x;
103
- };
104
-
105
- if (!offset) {
106
- offset = 0;
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
- dtype = data.slice(offset, offset + 1);
109
-
110
- dataoffset = offset + 2;
111
-
112
- switch (dtype) {
113
- case 'i':
114
- typeconvert = function typeconvert(x) {
115
- return parseInt(x, 10);
116
- };
117
- readData = readUntil(data, dataoffset, ';');
118
- chrs = readData[0];
119
- readdata = readData[1];
120
- dataoffset += chrs + 1;
121
- break;
122
- case 'b':
123
- typeconvert = function typeconvert(x) {
124
- var value = parseInt(x, 10);
125
-
126
- switch (value) {
127
- case 0:
128
- return false;
129
- case 1:
130
- return true;
131
- default:
132
- throw SyntaxError('Invalid boolean value');
133
- }
134
- };
135
- readData = readUntil(data, dataoffset, ';');
136
- chrs = readData[0];
137
- readdata = readData[1];
138
- dataoffset += chrs + 1;
139
- break;
140
- case 'd':
141
- typeconvert = function typeconvert(x) {
142
- return parseFloat(x);
143
- };
144
- readData = readUntil(data, dataoffset, ';');
145
- chrs = readData[0];
146
- readdata = readData[1];
147
- dataoffset += chrs + 1;
148
- break;
149
- case 'n':
150
- readdata = null;
151
- break;
152
- case 's':
153
- ccount = readUntil(data, dataoffset, ':');
154
- chrs = ccount[0];
155
- stringlength = ccount[1];
156
- dataoffset += chrs + 2;
157
-
158
- readData = readChrs(data, dataoffset + 1, parseInt(stringlength, 10));
159
- chrs = readData[0];
160
- readdata = readData[1];
161
- dataoffset += chrs + 2;
162
- if (chrs !== parseInt(stringlength, 10) && chrs !== readdata.length) {
163
- throw SyntaxError('String length mismatch');
164
- }
165
- break;
166
- case 'a':
167
- readdata = {};
168
-
169
- keyandchrs = readUntil(data, dataoffset, ':');
170
- chrs = keyandchrs[0];
171
- keys = keyandchrs[1];
172
- dataoffset += chrs + 2;
173
-
174
- length = parseInt(keys, 10);
175
- contig = true;
176
-
177
- for (i = 0; i < length; i++) {
178
- kprops = _unserialize(data, dataoffset);
179
- kchrs = kprops[1];
180
- key = kprops[2];
181
- dataoffset += kchrs;
182
-
183
- vprops = _unserialize(data, dataoffset);
184
- vchrs = vprops[1];
185
- value = vprops[2];
186
- dataoffset += vchrs;
187
-
188
- if (key !== i) {
189
- contig = false;
190
- }
191
-
192
- readdata[key] = value;
193
- }
194
-
195
- if (contig) {
196
- array = new Array(length);
197
- for (i = 0; i < length; i++) {
198
- array[i] = readdata[i];
199
- }
200
- readdata = array;
201
- }
202
-
203
- dataoffset += 1;
204
- break;
205
- case 'O':
206
- {
207
- // O:<class name length>:"class name":<prop count>:{<props and values>}
208
- // O:8:"stdClass":2:{s:3:"foo";s:3:"bar";s:3:"bar";s:3:"baz";}
209
- readData = readUntil(data, dataoffset, ':'); // read class name length
210
- dataoffset += readData[0] + 1;
211
- readData = readUntil(data, dataoffset, ':');
212
-
213
- if (readData[1] !== '"stdClass"') {
214
- throw Error('Unsupported object type: ' + readData[1]);
215
- }
216
-
217
- dataoffset += readData[0] + 1; // skip ":"
218
- readData = readUntil(data, dataoffset, ':');
219
- keys = parseInt(readData[1], 10);
220
-
221
- dataoffset += readData[0] + 2; // skip ":{"
222
- obj = {};
223
-
224
- for (i = 0; i < keys; i++) {
225
- readData = _unserialize(data, dataoffset);
226
- key = readData[2];
227
- dataoffset += readData[1];
228
-
229
- readData = _unserialize(data, dataoffset);
230
- dataoffset += readData[1];
231
- obj[key] = readData[2];
232
- }
233
-
234
- dataoffset += 1; // skip "}"
235
- readdata = obj;
236
- break;
237
- }
238
- default:
239
- throw SyntaxError('Unknown / Unhandled data type(s): ' + dtype);
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
- return [dtype, dataoffset - offset, typeconvert(readdata)];
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 data !== 'string') {
431
+ if (typeof str !== 'string') {
246
432
  return false;
247
433
  }
248
434
 
249
- return _unserialize(data, 0)[2];
435
+ return expectType(str, initCache())[0];
250
436
  } catch (err) {
251
437
  console.error(err);
252
438
  return false;