es6-crawler-detect 3.1.0 → 3.2.0

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 (351) hide show
  1. package/.babelrc +2 -1
  2. package/.eslintignore +6 -0
  3. package/.eslintrc.json +30 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +11 -8
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +1 -1
  6. package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +29 -0
  7. package/.prettierrc.json +5 -0
  8. package/README.md +27 -17
  9. package/dist/main.bundle.js +1 -1
  10. package/example/node/dist/crawler.min.js +1 -1
  11. package/example/node/node_modules/.bin/mime +15 -0
  12. package/example/node/node_modules/.bin/mime.cmd +7 -0
  13. package/example/node/node_modules/.yarn-integrity +67 -0
  14. package/example/node/node_modules/accepts/HISTORY.md +236 -0
  15. package/example/node/node_modules/accepts/LICENSE +23 -0
  16. package/example/node/node_modules/accepts/README.md +142 -0
  17. package/example/node/node_modules/accepts/index.js +238 -0
  18. package/example/node/node_modules/accepts/package.json +47 -0
  19. package/example/node/node_modules/array-flatten/LICENSE +21 -0
  20. package/example/node/node_modules/array-flatten/README.md +43 -0
  21. package/example/node/node_modules/array-flatten/array-flatten.js +64 -0
  22. package/example/node/node_modules/array-flatten/package.json +39 -0
  23. package/example/node/node_modules/body-parser/HISTORY.md +624 -0
  24. package/example/node/node_modules/body-parser/LICENSE +23 -0
  25. package/example/node/node_modules/body-parser/README.md +456 -0
  26. package/example/node/node_modules/body-parser/index.js +157 -0
  27. package/example/node/node_modules/body-parser/lib/read.js +181 -0
  28. package/example/node/node_modules/body-parser/lib/types/json.js +230 -0
  29. package/example/node/node_modules/body-parser/lib/types/raw.js +101 -0
  30. package/example/node/node_modules/body-parser/lib/types/text.js +121 -0
  31. package/example/node/node_modules/body-parser/lib/types/urlencoded.js +284 -0
  32. package/example/node/node_modules/body-parser/package.json +52 -0
  33. package/example/node/node_modules/bytes/History.md +92 -0
  34. package/example/node/node_modules/bytes/LICENSE +23 -0
  35. package/example/node/node_modules/bytes/Readme.md +152 -0
  36. package/example/node/node_modules/bytes/index.js +166 -0
  37. package/example/node/node_modules/bytes/package.json +42 -0
  38. package/example/node/node_modules/content-disposition/HISTORY.md +60 -0
  39. package/example/node/node_modules/content-disposition/LICENSE +22 -0
  40. package/example/node/node_modules/content-disposition/README.md +142 -0
  41. package/example/node/node_modules/content-disposition/index.js +458 -0
  42. package/example/node/node_modules/content-disposition/package.json +44 -0
  43. package/example/node/node_modules/content-type/HISTORY.md +24 -0
  44. package/example/node/node_modules/content-type/LICENSE +22 -0
  45. package/example/node/node_modules/content-type/README.md +92 -0
  46. package/example/node/node_modules/content-type/index.js +222 -0
  47. package/example/node/node_modules/content-type/package.json +40 -0
  48. package/example/node/node_modules/cookie/HISTORY.md +128 -0
  49. package/example/node/node_modules/cookie/LICENSE +24 -0
  50. package/example/node/node_modules/cookie/README.md +257 -0
  51. package/example/node/node_modules/cookie/index.js +202 -0
  52. package/example/node/node_modules/cookie/package.json +40 -0
  53. package/example/node/node_modules/cookie-signature/History.md +38 -0
  54. package/example/node/node_modules/cookie-signature/Readme.md +42 -0
  55. package/example/node/node_modules/cookie-signature/index.js +51 -0
  56. package/example/node/node_modules/cookie-signature/package.json +18 -0
  57. package/example/node/node_modules/debug/.coveralls.yml +1 -0
  58. package/example/node/node_modules/debug/.eslintrc +11 -0
  59. package/example/node/node_modules/debug/.travis.yml +14 -0
  60. package/example/node/node_modules/debug/CHANGELOG.md +362 -0
  61. package/example/node/node_modules/debug/LICENSE +19 -0
  62. package/example/node/node_modules/debug/Makefile +50 -0
  63. package/example/node/node_modules/debug/README.md +312 -0
  64. package/example/node/node_modules/debug/component.json +19 -0
  65. package/example/node/node_modules/debug/karma.conf.js +70 -0
  66. package/example/node/node_modules/debug/node.js +1 -0
  67. package/example/node/node_modules/debug/package.json +49 -0
  68. package/example/node/node_modules/debug/src/browser.js +185 -0
  69. package/example/node/node_modules/debug/src/debug.js +202 -0
  70. package/example/node/node_modules/debug/src/index.js +10 -0
  71. package/example/node/node_modules/debug/src/inspector-log.js +15 -0
  72. package/example/node/node_modules/debug/src/node.js +248 -0
  73. package/example/node/node_modules/depd/History.md +96 -0
  74. package/example/node/node_modules/depd/LICENSE +22 -0
  75. package/example/node/node_modules/depd/Readme.md +280 -0
  76. package/example/node/node_modules/depd/index.js +522 -0
  77. package/example/node/node_modules/depd/lib/browser/index.js +77 -0
  78. package/example/node/node_modules/depd/lib/compat/callsite-tostring.js +103 -0
  79. package/example/node/node_modules/depd/lib/compat/event-listener-count.js +22 -0
  80. package/example/node/node_modules/depd/lib/compat/index.js +79 -0
  81. package/example/node/node_modules/depd/package.json +41 -0
  82. package/example/node/node_modules/destroy/LICENSE +22 -0
  83. package/example/node/node_modules/destroy/README.md +60 -0
  84. package/example/node/node_modules/destroy/index.js +75 -0
  85. package/example/node/node_modules/destroy/package.json +37 -0
  86. package/example/node/node_modules/ee-first/LICENSE +22 -0
  87. package/example/node/node_modules/ee-first/README.md +80 -0
  88. package/example/node/node_modules/ee-first/index.js +95 -0
  89. package/example/node/node_modules/ee-first/package.json +29 -0
  90. package/example/node/node_modules/encodeurl/HISTORY.md +14 -0
  91. package/example/node/node_modules/encodeurl/LICENSE +22 -0
  92. package/example/node/node_modules/encodeurl/README.md +128 -0
  93. package/example/node/node_modules/encodeurl/index.js +60 -0
  94. package/example/node/node_modules/encodeurl/package.json +40 -0
  95. package/example/node/node_modules/escape-html/LICENSE +24 -0
  96. package/example/node/node_modules/escape-html/Readme.md +43 -0
  97. package/example/node/node_modules/escape-html/index.js +78 -0
  98. package/example/node/node_modules/escape-html/package.json +24 -0
  99. package/example/node/node_modules/etag/HISTORY.md +83 -0
  100. package/example/node/node_modules/etag/LICENSE +22 -0
  101. package/example/node/node_modules/etag/README.md +159 -0
  102. package/example/node/node_modules/etag/index.js +131 -0
  103. package/example/node/node_modules/etag/package.json +47 -0
  104. package/example/node/node_modules/express/History.md +3510 -0
  105. package/example/node/node_modules/express/LICENSE +24 -0
  106. package/example/node/node_modules/express/Readme.md +158 -0
  107. package/example/node/node_modules/express/index.js +11 -0
  108. package/example/node/node_modules/express/lib/application.js +644 -0
  109. package/example/node/node_modules/express/lib/express.js +116 -0
  110. package/example/node/node_modules/express/lib/middleware/init.js +43 -0
  111. package/example/node/node_modules/express/lib/middleware/query.js +47 -0
  112. package/example/node/node_modules/express/lib/request.js +525 -0
  113. package/example/node/node_modules/express/lib/response.js +1147 -0
  114. package/example/node/node_modules/express/lib/router/index.js +668 -0
  115. package/example/node/node_modules/express/lib/router/layer.js +181 -0
  116. package/example/node/node_modules/express/lib/router/route.js +216 -0
  117. package/example/node/node_modules/express/lib/utils.js +302 -0
  118. package/example/node/node_modules/express/lib/view.js +182 -0
  119. package/example/node/node_modules/express/package.json +99 -0
  120. package/example/node/node_modules/finalhandler/HISTORY.md +187 -0
  121. package/example/node/node_modules/finalhandler/LICENSE +22 -0
  122. package/example/node/node_modules/finalhandler/README.md +148 -0
  123. package/example/node/node_modules/finalhandler/index.js +331 -0
  124. package/example/node/node_modules/finalhandler/package.json +45 -0
  125. package/example/node/node_modules/forwarded/HISTORY.md +21 -0
  126. package/example/node/node_modules/forwarded/LICENSE +22 -0
  127. package/example/node/node_modules/forwarded/README.md +57 -0
  128. package/example/node/node_modules/forwarded/index.js +90 -0
  129. package/example/node/node_modules/forwarded/package.json +45 -0
  130. package/example/node/node_modules/fresh/HISTORY.md +70 -0
  131. package/example/node/node_modules/fresh/LICENSE +23 -0
  132. package/example/node/node_modules/fresh/README.md +119 -0
  133. package/example/node/node_modules/fresh/index.js +137 -0
  134. package/example/node/node_modules/fresh/package.json +46 -0
  135. package/example/node/node_modules/http-errors/HISTORY.md +165 -0
  136. package/example/node/node_modules/http-errors/LICENSE +23 -0
  137. package/example/node/node_modules/http-errors/README.md +169 -0
  138. package/example/node/node_modules/http-errors/index.js +299 -0
  139. package/example/node/node_modules/http-errors/package.json +49 -0
  140. package/example/node/node_modules/iconv-lite/Changelog.md +162 -0
  141. package/example/node/node_modules/iconv-lite/LICENSE +21 -0
  142. package/example/node/node_modules/iconv-lite/README.md +156 -0
  143. package/example/node/node_modules/iconv-lite/encodings/dbcs-codec.js +555 -0
  144. package/example/node/node_modules/iconv-lite/encodings/dbcs-data.js +176 -0
  145. package/example/node/node_modules/iconv-lite/encodings/index.js +22 -0
  146. package/example/node/node_modules/iconv-lite/encodings/internal.js +188 -0
  147. package/example/node/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
  148. package/example/node/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  149. package/example/node/node_modules/iconv-lite/encodings/sbcs-data.js +174 -0
  150. package/example/node/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  151. package/example/node/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  152. package/example/node/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  153. package/example/node/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  154. package/example/node/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  155. package/example/node/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  156. package/example/node/node_modules/iconv-lite/encodings/tables/gbk-added.json +55 -0
  157. package/example/node/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  158. package/example/node/node_modules/iconv-lite/encodings/utf16.js +177 -0
  159. package/example/node/node_modules/iconv-lite/encodings/utf7.js +290 -0
  160. package/example/node/node_modules/iconv-lite/lib/bom-handling.js +52 -0
  161. package/example/node/node_modules/iconv-lite/lib/extend-node.js +217 -0
  162. package/example/node/node_modules/iconv-lite/lib/index.d.ts +24 -0
  163. package/example/node/node_modules/iconv-lite/lib/index.js +153 -0
  164. package/example/node/node_modules/iconv-lite/lib/streams.js +121 -0
  165. package/example/node/node_modules/iconv-lite/package.json +46 -0
  166. package/example/node/node_modules/inherits/LICENSE +16 -0
  167. package/example/node/node_modules/inherits/README.md +42 -0
  168. package/example/node/node_modules/inherits/inherits.js +9 -0
  169. package/example/node/node_modules/inherits/inherits_browser.js +27 -0
  170. package/example/node/node_modules/inherits/package.json +29 -0
  171. package/example/node/node_modules/ipaddr.js/LICENSE +19 -0
  172. package/example/node/node_modules/ipaddr.js/README.md +233 -0
  173. package/example/node/node_modules/ipaddr.js/ipaddr.min.js +1 -0
  174. package/example/node/node_modules/ipaddr.js/lib/ipaddr.js +673 -0
  175. package/example/node/node_modules/ipaddr.js/lib/ipaddr.js.d.ts +68 -0
  176. package/example/node/node_modules/ipaddr.js/package.json +35 -0
  177. package/example/node/node_modules/media-typer/HISTORY.md +22 -0
  178. package/example/node/node_modules/media-typer/LICENSE +22 -0
  179. package/example/node/node_modules/media-typer/README.md +81 -0
  180. package/example/node/node_modules/media-typer/index.js +270 -0
  181. package/example/node/node_modules/media-typer/package.json +26 -0
  182. package/example/node/node_modules/merge-descriptors/HISTORY.md +21 -0
  183. package/example/node/node_modules/merge-descriptors/LICENSE +23 -0
  184. package/example/node/node_modules/merge-descriptors/README.md +48 -0
  185. package/example/node/node_modules/merge-descriptors/index.js +60 -0
  186. package/example/node/node_modules/merge-descriptors/package.json +32 -0
  187. package/example/node/node_modules/methods/HISTORY.md +29 -0
  188. package/example/node/node_modules/methods/LICENSE +24 -0
  189. package/example/node/node_modules/methods/README.md +51 -0
  190. package/example/node/node_modules/methods/index.js +69 -0
  191. package/example/node/node_modules/methods/package.json +36 -0
  192. package/example/node/node_modules/mime/CHANGELOG.md +164 -0
  193. package/example/node/node_modules/mime/LICENSE +21 -0
  194. package/example/node/node_modules/mime/README.md +90 -0
  195. package/example/node/node_modules/mime/cli.js +8 -0
  196. package/example/node/node_modules/mime/mime.js +108 -0
  197. package/example/node/node_modules/mime/package.json +44 -0
  198. package/example/node/node_modules/mime/src/build.js +53 -0
  199. package/example/node/node_modules/mime/src/test.js +60 -0
  200. package/example/node/node_modules/mime/types.json +1 -0
  201. package/example/node/node_modules/mime-db/HISTORY.md +499 -0
  202. package/example/node/node_modules/mime-db/LICENSE +22 -0
  203. package/example/node/node_modules/mime-db/README.md +100 -0
  204. package/example/node/node_modules/mime-db/db.json +8471 -0
  205. package/example/node/node_modules/mime-db/index.js +11 -0
  206. package/example/node/node_modules/mime-db/package.json +59 -0
  207. package/example/node/node_modules/mime-types/HISTORY.md +388 -0
  208. package/example/node/node_modules/mime-types/LICENSE +23 -0
  209. package/example/node/node_modules/mime-types/README.md +113 -0
  210. package/example/node/node_modules/mime-types/index.js +188 -0
  211. package/example/node/node_modules/mime-types/package.json +44 -0
  212. package/example/node/node_modules/ms/index.js +152 -0
  213. package/example/node/node_modules/ms/license.md +21 -0
  214. package/example/node/node_modules/ms/package.json +37 -0
  215. package/example/node/node_modules/ms/readme.md +51 -0
  216. package/example/node/node_modules/negotiator/HISTORY.md +103 -0
  217. package/example/node/node_modules/negotiator/LICENSE +24 -0
  218. package/example/node/node_modules/negotiator/README.md +203 -0
  219. package/example/node/node_modules/negotiator/index.js +124 -0
  220. package/example/node/node_modules/negotiator/lib/charset.js +169 -0
  221. package/example/node/node_modules/negotiator/lib/encoding.js +184 -0
  222. package/example/node/node_modules/negotiator/lib/language.js +179 -0
  223. package/example/node/node_modules/negotiator/lib/mediaType.js +294 -0
  224. package/example/node/node_modules/negotiator/package.json +42 -0
  225. package/example/node/node_modules/on-finished/HISTORY.md +88 -0
  226. package/example/node/node_modules/on-finished/LICENSE +23 -0
  227. package/example/node/node_modules/on-finished/README.md +154 -0
  228. package/example/node/node_modules/on-finished/index.js +196 -0
  229. package/example/node/node_modules/on-finished/package.json +31 -0
  230. package/example/node/node_modules/parseurl/HISTORY.md +58 -0
  231. package/example/node/node_modules/parseurl/LICENSE +24 -0
  232. package/example/node/node_modules/parseurl/README.md +133 -0
  233. package/example/node/node_modules/parseurl/index.js +158 -0
  234. package/example/node/node_modules/parseurl/package.json +40 -0
  235. package/example/node/node_modules/path-to-regexp/History.md +36 -0
  236. package/example/node/node_modules/path-to-regexp/LICENSE +21 -0
  237. package/example/node/node_modules/path-to-regexp/Readme.md +35 -0
  238. package/example/node/node_modules/path-to-regexp/index.js +129 -0
  239. package/example/node/node_modules/path-to-regexp/package.json +30 -0
  240. package/example/node/node_modules/proxy-addr/HISTORY.md +161 -0
  241. package/example/node/node_modules/proxy-addr/LICENSE +22 -0
  242. package/example/node/node_modules/proxy-addr/README.md +139 -0
  243. package/example/node/node_modules/proxy-addr/index.js +327 -0
  244. package/example/node/node_modules/proxy-addr/package.json +47 -0
  245. package/example/node/node_modules/qs/.editorconfig +39 -0
  246. package/example/node/node_modules/qs/.eslintignore +2 -0
  247. package/example/node/node_modules/qs/.eslintrc +35 -0
  248. package/example/node/node_modules/qs/.github/FUNDING.yml +12 -0
  249. package/example/node/node_modules/qs/.nycrc +13 -0
  250. package/example/node/node_modules/qs/CHANGELOG.md +359 -0
  251. package/example/node/node_modules/qs/LICENSE.md +29 -0
  252. package/example/node/node_modules/qs/README.md +604 -0
  253. package/example/node/node_modules/qs/dist/qs.js +832 -0
  254. package/example/node/node_modules/qs/lib/formats.js +23 -0
  255. package/example/node/node_modules/qs/lib/index.js +11 -0
  256. package/example/node/node_modules/qs/lib/parse.js +257 -0
  257. package/example/node/node_modules/qs/lib/stringify.js +278 -0
  258. package/example/node/node_modules/qs/lib/utils.js +251 -0
  259. package/example/node/node_modules/qs/package.json +69 -0
  260. package/example/node/node_modules/qs/test/parse.js +772 -0
  261. package/example/node/node_modules/qs/test/stringify.js +793 -0
  262. package/example/node/node_modules/qs/test/utils.js +136 -0
  263. package/example/node/node_modules/range-parser/HISTORY.md +56 -0
  264. package/example/node/node_modules/range-parser/LICENSE +23 -0
  265. package/example/node/node_modules/range-parser/README.md +84 -0
  266. package/example/node/node_modules/range-parser/index.js +162 -0
  267. package/example/node/node_modules/range-parser/package.json +44 -0
  268. package/example/node/node_modules/raw-body/HISTORY.md +284 -0
  269. package/example/node/node_modules/raw-body/LICENSE +22 -0
  270. package/example/node/node_modules/raw-body/README.md +217 -0
  271. package/example/node/node_modules/raw-body/index.d.ts +87 -0
  272. package/example/node/node_modules/raw-body/index.js +286 -0
  273. package/example/node/node_modules/raw-body/package.json +48 -0
  274. package/example/node/node_modules/safe-buffer/LICENSE +21 -0
  275. package/example/node/node_modules/safe-buffer/README.md +584 -0
  276. package/example/node/node_modules/safe-buffer/index.d.ts +187 -0
  277. package/example/node/node_modules/safe-buffer/index.js +65 -0
  278. package/example/node/node_modules/safe-buffer/package.json +51 -0
  279. package/example/node/node_modules/safer-buffer/LICENSE +21 -0
  280. package/example/node/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  281. package/example/node/node_modules/safer-buffer/Readme.md +156 -0
  282. package/example/node/node_modules/safer-buffer/dangerous.js +58 -0
  283. package/example/node/node_modules/safer-buffer/package.json +34 -0
  284. package/example/node/node_modules/safer-buffer/safer.js +77 -0
  285. package/example/node/node_modules/safer-buffer/tests.js +406 -0
  286. package/example/node/node_modules/send/HISTORY.md +506 -0
  287. package/example/node/node_modules/send/LICENSE +23 -0
  288. package/example/node/node_modules/send/README.md +327 -0
  289. package/example/node/node_modules/send/index.js +1133 -0
  290. package/example/node/node_modules/send/node_modules/.bin/mime +15 -0
  291. package/example/node/node_modules/send/node_modules/.bin/mime.cmd +7 -0
  292. package/example/node/node_modules/send/node_modules/ms/index.js +162 -0
  293. package/example/node/node_modules/send/node_modules/ms/license.md +21 -0
  294. package/example/node/node_modules/send/node_modules/ms/package.json +38 -0
  295. package/example/node/node_modules/send/node_modules/ms/readme.md +59 -0
  296. package/example/node/node_modules/send/package.json +61 -0
  297. package/example/node/node_modules/serve-static/HISTORY.md +459 -0
  298. package/example/node/node_modules/serve-static/LICENSE +25 -0
  299. package/example/node/node_modules/serve-static/README.md +257 -0
  300. package/example/node/node_modules/serve-static/index.js +210 -0
  301. package/example/node/node_modules/serve-static/package.json +42 -0
  302. package/example/node/node_modules/setprototypeof/LICENSE +13 -0
  303. package/example/node/node_modules/setprototypeof/README.md +31 -0
  304. package/example/node/node_modules/setprototypeof/index.d.ts +2 -0
  305. package/example/node/node_modules/setprototypeof/index.js +17 -0
  306. package/example/node/node_modules/setprototypeof/package.json +38 -0
  307. package/example/node/node_modules/setprototypeof/test/index.js +24 -0
  308. package/example/node/node_modules/statuses/HISTORY.md +65 -0
  309. package/example/node/node_modules/statuses/LICENSE +23 -0
  310. package/example/node/node_modules/statuses/README.md +127 -0
  311. package/example/node/node_modules/statuses/codes.json +66 -0
  312. package/example/node/node_modules/statuses/index.js +113 -0
  313. package/example/node/node_modules/statuses/package.json +48 -0
  314. package/example/node/node_modules/toidentifier/HISTORY.md +9 -0
  315. package/example/node/node_modules/toidentifier/LICENSE +21 -0
  316. package/example/node/node_modules/toidentifier/README.md +61 -0
  317. package/example/node/node_modules/toidentifier/index.js +32 -0
  318. package/example/node/node_modules/toidentifier/package.json +38 -0
  319. package/example/node/node_modules/type-is/HISTORY.md +259 -0
  320. package/example/node/node_modules/type-is/LICENSE +23 -0
  321. package/example/node/node_modules/type-is/README.md +170 -0
  322. package/example/node/node_modules/type-is/index.js +266 -0
  323. package/example/node/node_modules/type-is/package.json +45 -0
  324. package/example/node/node_modules/unpipe/HISTORY.md +4 -0
  325. package/example/node/node_modules/unpipe/LICENSE +22 -0
  326. package/example/node/node_modules/unpipe/README.md +43 -0
  327. package/example/node/node_modules/unpipe/index.js +69 -0
  328. package/example/node/node_modules/unpipe/package.json +27 -0
  329. package/example/node/node_modules/utils-merge/LICENSE +20 -0
  330. package/example/node/node_modules/utils-merge/README.md +34 -0
  331. package/example/node/node_modules/utils-merge/index.js +23 -0
  332. package/example/node/node_modules/utils-merge/package.json +40 -0
  333. package/example/node/node_modules/vary/HISTORY.md +39 -0
  334. package/example/node/node_modules/vary/LICENSE +22 -0
  335. package/example/node/node_modules/vary/README.md +101 -0
  336. package/example/node/node_modules/vary/index.js +149 -0
  337. package/example/node/node_modules/vary/package.json +43 -0
  338. package/example/node/package.json +11 -0
  339. package/example/node/server.js +32 -26
  340. package/example/node/yarn.lock +352 -0
  341. package/package.json +30 -19
  342. package/src/index.js +16 -10
  343. package/src/lib/crawler/crawlers.js +1402 -15
  344. package/src/lib/crawler/exclusions.js +62 -15
  345. package/src/lib/crawler/headers.js +24 -15
  346. package/src/lib/crawler/provider.js +11 -13
  347. package/src/lib/crawler.js +135 -139
  348. package/test/lib/crawler.test.js +52 -35
  349. package/webpack.common.js +20 -20
  350. package/webpack.dev.js +7 -7
  351. package/webpack.prod.js +14 -15
@@ -0,0 +1,772 @@
1
+ 'use strict';
2
+
3
+ var test = require('tape');
4
+ var qs = require('../');
5
+ var utils = require('../lib/utils');
6
+ var iconv = require('iconv-lite');
7
+ var SaferBuffer = require('safer-buffer').Buffer;
8
+
9
+ test('parse()', function (t) {
10
+ t.test('parses a simple string', function (st) {
11
+ st.deepEqual(qs.parse('0=foo'), { 0: 'foo' });
12
+ st.deepEqual(qs.parse('foo=c++'), { foo: 'c ' });
13
+ st.deepEqual(qs.parse('a[>=]=23'), { a: { '>=': '23' } });
14
+ st.deepEqual(qs.parse('a[<=>]==23'), { a: { '<=>': '=23' } });
15
+ st.deepEqual(qs.parse('a[==]=23'), { a: { '==': '23' } });
16
+ st.deepEqual(qs.parse('foo', { strictNullHandling: true }), { foo: null });
17
+ st.deepEqual(qs.parse('foo'), { foo: '' });
18
+ st.deepEqual(qs.parse('foo='), { foo: '' });
19
+ st.deepEqual(qs.parse('foo=bar'), { foo: 'bar' });
20
+ st.deepEqual(qs.parse(' foo = bar = baz '), { ' foo ': ' bar = baz ' });
21
+ st.deepEqual(qs.parse('foo=bar=baz'), { foo: 'bar=baz' });
22
+ st.deepEqual(qs.parse('foo=bar&bar=baz'), { foo: 'bar', bar: 'baz' });
23
+ st.deepEqual(qs.parse('foo2=bar2&baz2='), { foo2: 'bar2', baz2: '' });
24
+ st.deepEqual(qs.parse('foo=bar&baz', { strictNullHandling: true }), { foo: 'bar', baz: null });
25
+ st.deepEqual(qs.parse('foo=bar&baz'), { foo: 'bar', baz: '' });
26
+ st.deepEqual(qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World'), {
27
+ cht: 'p3',
28
+ chd: 't:60,40',
29
+ chs: '250x100',
30
+ chl: 'Hello|World'
31
+ });
32
+ st.end();
33
+ });
34
+
35
+ t.test('arrayFormat: brackets allows only explicit arrays', function (st) {
36
+ st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
37
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
38
+ st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'brackets' }), { a: 'b,c' });
39
+ st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
40
+ st.end();
41
+ });
42
+
43
+ t.test('arrayFormat: indices allows only indexed arrays', function (st) {
44
+ st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
45
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
46
+ st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'indices' }), { a: 'b,c' });
47
+ st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
48
+ st.end();
49
+ });
50
+
51
+ t.test('arrayFormat: comma allows only comma-separated arrays', function (st) {
52
+ st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
53
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
54
+ st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'comma' }), { a: 'b,c' });
55
+ st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
56
+ st.end();
57
+ });
58
+
59
+ t.test('arrayFormat: repeat allows only repeated values', function (st) {
60
+ st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
61
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
62
+ st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'repeat' }), { a: 'b,c' });
63
+ st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
64
+ st.end();
65
+ });
66
+
67
+ t.test('allows enabling dot notation', function (st) {
68
+ st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });
69
+ st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });
70
+ st.end();
71
+ });
72
+
73
+ t.deepEqual(qs.parse('a[b]=c'), { a: { b: 'c' } }, 'parses a single nested string');
74
+ t.deepEqual(qs.parse('a[b][c]=d'), { a: { b: { c: 'd' } } }, 'parses a double nested string');
75
+ t.deepEqual(
76
+ qs.parse('a[b][c][d][e][f][g][h]=i'),
77
+ { a: { b: { c: { d: { e: { f: { '[g][h]': 'i' } } } } } } },
78
+ 'defaults to a depth of 5'
79
+ );
80
+
81
+ t.test('only parses one level when depth = 1', function (st) {
82
+ st.deepEqual(qs.parse('a[b][c]=d', { depth: 1 }), { a: { b: { '[c]': 'd' } } });
83
+ st.deepEqual(qs.parse('a[b][c][d]=e', { depth: 1 }), { a: { b: { '[c][d]': 'e' } } });
84
+ st.end();
85
+ });
86
+
87
+ t.test('uses original key when depth = 0', function (st) {
88
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: 0 }), { 'a[0]': 'b', 'a[1]': 'c' });
89
+ st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: 0 }), { 'a[0][0]': 'b', 'a[0][1]': 'c', 'a[1]': 'd', e: '2' });
90
+ st.end();
91
+ });
92
+
93
+ t.test('uses original key when depth = false', function (st) {
94
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: false }), { 'a[0]': 'b', 'a[1]': 'c' });
95
+ st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: false }), { 'a[0][0]': 'b', 'a[0][1]': 'c', 'a[1]': 'd', e: '2' });
96
+ st.end();
97
+ });
98
+
99
+ t.deepEqual(qs.parse('a=b&a=c'), { a: ['b', 'c'] }, 'parses a simple array');
100
+
101
+ t.test('parses an explicit array', function (st) {
102
+ st.deepEqual(qs.parse('a[]=b'), { a: ['b'] });
103
+ st.deepEqual(qs.parse('a[]=b&a[]=c'), { a: ['b', 'c'] });
104
+ st.deepEqual(qs.parse('a[]=b&a[]=c&a[]=d'), { a: ['b', 'c', 'd'] });
105
+ st.end();
106
+ });
107
+
108
+ t.test('parses a mix of simple and explicit arrays', function (st) {
109
+ st.deepEqual(qs.parse('a=b&a[]=c'), { a: ['b', 'c'] });
110
+ st.deepEqual(qs.parse('a[]=b&a=c'), { a: ['b', 'c'] });
111
+ st.deepEqual(qs.parse('a[0]=b&a=c'), { a: ['b', 'c'] });
112
+ st.deepEqual(qs.parse('a=b&a[0]=c'), { a: ['b', 'c'] });
113
+
114
+ st.deepEqual(qs.parse('a[1]=b&a=c', { arrayLimit: 20 }), { a: ['b', 'c'] });
115
+ st.deepEqual(qs.parse('a[]=b&a=c', { arrayLimit: 0 }), { a: ['b', 'c'] });
116
+ st.deepEqual(qs.parse('a[]=b&a=c'), { a: ['b', 'c'] });
117
+
118
+ st.deepEqual(qs.parse('a=b&a[1]=c', { arrayLimit: 20 }), { a: ['b', 'c'] });
119
+ st.deepEqual(qs.parse('a=b&a[]=c', { arrayLimit: 0 }), { a: ['b', 'c'] });
120
+ st.deepEqual(qs.parse('a=b&a[]=c'), { a: ['b', 'c'] });
121
+
122
+ st.end();
123
+ });
124
+
125
+ t.test('parses a nested array', function (st) {
126
+ st.deepEqual(qs.parse('a[b][]=c&a[b][]=d'), { a: { b: ['c', 'd'] } });
127
+ st.deepEqual(qs.parse('a[>=]=25'), { a: { '>=': '25' } });
128
+ st.end();
129
+ });
130
+
131
+ t.test('allows to specify array indices', function (st) {
132
+ st.deepEqual(qs.parse('a[1]=c&a[0]=b&a[2]=d'), { a: ['b', 'c', 'd'] });
133
+ st.deepEqual(qs.parse('a[1]=c&a[0]=b'), { a: ['b', 'c'] });
134
+ st.deepEqual(qs.parse('a[1]=c', { arrayLimit: 20 }), { a: ['c'] });
135
+ st.deepEqual(qs.parse('a[1]=c', { arrayLimit: 0 }), { a: { 1: 'c' } });
136
+ st.deepEqual(qs.parse('a[1]=c'), { a: ['c'] });
137
+ st.end();
138
+ });
139
+
140
+ t.test('limits specific array indices to arrayLimit', function (st) {
141
+ st.deepEqual(qs.parse('a[20]=a', { arrayLimit: 20 }), { a: ['a'] });
142
+ st.deepEqual(qs.parse('a[21]=a', { arrayLimit: 20 }), { a: { 21: 'a' } });
143
+ st.end();
144
+ });
145
+
146
+ t.deepEqual(qs.parse('a[12b]=c'), { a: { '12b': 'c' } }, 'supports keys that begin with a number');
147
+
148
+ t.test('supports encoded = signs', function (st) {
149
+ st.deepEqual(qs.parse('he%3Dllo=th%3Dere'), { 'he=llo': 'th=ere' });
150
+ st.end();
151
+ });
152
+
153
+ t.test('is ok with url encoded strings', function (st) {
154
+ st.deepEqual(qs.parse('a[b%20c]=d'), { a: { 'b c': 'd' } });
155
+ st.deepEqual(qs.parse('a[b]=c%20d'), { a: { b: 'c d' } });
156
+ st.end();
157
+ });
158
+
159
+ t.test('allows brackets in the value', function (st) {
160
+ st.deepEqual(qs.parse('pets=["tobi"]'), { pets: '["tobi"]' });
161
+ st.deepEqual(qs.parse('operators=[">=", "<="]'), { operators: '[">=", "<="]' });
162
+ st.end();
163
+ });
164
+
165
+ t.test('allows empty values', function (st) {
166
+ st.deepEqual(qs.parse(''), {});
167
+ st.deepEqual(qs.parse(null), {});
168
+ st.deepEqual(qs.parse(undefined), {});
169
+ st.end();
170
+ });
171
+
172
+ t.test('transforms arrays to objects', function (st) {
173
+ st.deepEqual(qs.parse('foo[0]=bar&foo[bad]=baz'), { foo: { 0: 'bar', bad: 'baz' } });
174
+ st.deepEqual(qs.parse('foo[bad]=baz&foo[0]=bar'), { foo: { bad: 'baz', 0: 'bar' } });
175
+ st.deepEqual(qs.parse('foo[bad]=baz&foo[]=bar'), { foo: { bad: 'baz', 0: 'bar' } });
176
+ st.deepEqual(qs.parse('foo[]=bar&foo[bad]=baz'), { foo: { 0: 'bar', bad: 'baz' } });
177
+ st.deepEqual(qs.parse('foo[bad]=baz&foo[]=bar&foo[]=foo'), { foo: { bad: 'baz', 0: 'bar', 1: 'foo' } });
178
+ st.deepEqual(qs.parse('foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb'), { foo: [{ a: 'a', b: 'b' }, { a: 'aa', b: 'bb' }] });
179
+
180
+ st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: false }), { a: { 0: 'b', t: 'u' } });
181
+ st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: true }), { a: { 0: 'b', t: 'u', hasOwnProperty: 'c' } });
182
+ st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: false }), { a: { 0: 'b', x: 'y' } });
183
+ st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: true }), { a: { 0: 'b', hasOwnProperty: 'c', x: 'y' } });
184
+ st.end();
185
+ });
186
+
187
+ t.test('transforms arrays to objects (dot notation)', function (st) {
188
+ st.deepEqual(qs.parse('foo[0].baz=bar&fool.bad=baz', { allowDots: true }), { foo: [{ baz: 'bar' }], fool: { bad: 'baz' } });
189
+ st.deepEqual(qs.parse('foo[0].baz=bar&fool.bad.boo=baz', { allowDots: true }), { foo: [{ baz: 'bar' }], fool: { bad: { boo: 'baz' } } });
190
+ st.deepEqual(qs.parse('foo[0][0].baz=bar&fool.bad=baz', { allowDots: true }), { foo: [[{ baz: 'bar' }]], fool: { bad: 'baz' } });
191
+ st.deepEqual(qs.parse('foo[0].baz[0]=15&foo[0].bar=2', { allowDots: true }), { foo: [{ baz: ['15'], bar: '2' }] });
192
+ st.deepEqual(qs.parse('foo[0].baz[0]=15&foo[0].baz[1]=16&foo[0].bar=2', { allowDots: true }), { foo: [{ baz: ['15', '16'], bar: '2' }] });
193
+ st.deepEqual(qs.parse('foo.bad=baz&foo[0]=bar', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar' } });
194
+ st.deepEqual(qs.parse('foo.bad=baz&foo[]=bar', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar' } });
195
+ st.deepEqual(qs.parse('foo[]=bar&foo.bad=baz', { allowDots: true }), { foo: { 0: 'bar', bad: 'baz' } });
196
+ st.deepEqual(qs.parse('foo.bad=baz&foo[]=bar&foo[]=foo', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar', 1: 'foo' } });
197
+ st.deepEqual(qs.parse('foo[0].a=a&foo[0].b=b&foo[1].a=aa&foo[1].b=bb', { allowDots: true }), { foo: [{ a: 'a', b: 'b' }, { a: 'aa', b: 'bb' }] });
198
+ st.end();
199
+ });
200
+
201
+ t.test('correctly prunes undefined values when converting an array to an object', function (st) {
202
+ st.deepEqual(qs.parse('a[2]=b&a[99999999]=c'), { a: { 2: 'b', 99999999: 'c' } });
203
+ st.end();
204
+ });
205
+
206
+ t.test('supports malformed uri characters', function (st) {
207
+ st.deepEqual(qs.parse('{%:%}', { strictNullHandling: true }), { '{%:%}': null });
208
+ st.deepEqual(qs.parse('{%:%}='), { '{%:%}': '' });
209
+ st.deepEqual(qs.parse('foo=%:%}'), { foo: '%:%}' });
210
+ st.end();
211
+ });
212
+
213
+ t.test('doesn\'t produce empty keys', function (st) {
214
+ st.deepEqual(qs.parse('_r=1&'), { _r: '1' });
215
+ st.end();
216
+ });
217
+
218
+ t.test('cannot access Object prototype', function (st) {
219
+ qs.parse('constructor[prototype][bad]=bad');
220
+ qs.parse('bad[constructor][prototype][bad]=bad');
221
+ st.equal(typeof Object.prototype.bad, 'undefined');
222
+ st.end();
223
+ });
224
+
225
+ t.test('parses arrays of objects', function (st) {
226
+ st.deepEqual(qs.parse('a[][b]=c'), { a: [{ b: 'c' }] });
227
+ st.deepEqual(qs.parse('a[0][b]=c'), { a: [{ b: 'c' }] });
228
+ st.end();
229
+ });
230
+
231
+ t.test('allows for empty strings in arrays', function (st) {
232
+ st.deepEqual(qs.parse('a[]=b&a[]=&a[]=c'), { a: ['b', '', 'c'] });
233
+
234
+ st.deepEqual(
235
+ qs.parse('a[0]=b&a[1]&a[2]=c&a[19]=', { strictNullHandling: true, arrayLimit: 20 }),
236
+ { a: ['b', null, 'c', ''] },
237
+ 'with arrayLimit 20 + array indices: null then empty string works'
238
+ );
239
+ st.deepEqual(
240
+ qs.parse('a[]=b&a[]&a[]=c&a[]=', { strictNullHandling: true, arrayLimit: 0 }),
241
+ { a: ['b', null, 'c', ''] },
242
+ 'with arrayLimit 0 + array brackets: null then empty string works'
243
+ );
244
+
245
+ st.deepEqual(
246
+ qs.parse('a[0]=b&a[1]=&a[2]=c&a[19]', { strictNullHandling: true, arrayLimit: 20 }),
247
+ { a: ['b', '', 'c', null] },
248
+ 'with arrayLimit 20 + array indices: empty string then null works'
249
+ );
250
+ st.deepEqual(
251
+ qs.parse('a[]=b&a[]=&a[]=c&a[]', { strictNullHandling: true, arrayLimit: 0 }),
252
+ { a: ['b', '', 'c', null] },
253
+ 'with arrayLimit 0 + array brackets: empty string then null works'
254
+ );
255
+
256
+ st.deepEqual(
257
+ qs.parse('a[]=&a[]=b&a[]=c'),
258
+ { a: ['', 'b', 'c'] },
259
+ 'array brackets: empty strings work'
260
+ );
261
+ st.end();
262
+ });
263
+
264
+ t.test('compacts sparse arrays', function (st) {
265
+ st.deepEqual(qs.parse('a[10]=1&a[2]=2', { arrayLimit: 20 }), { a: ['2', '1'] });
266
+ st.deepEqual(qs.parse('a[1][b][2][c]=1', { arrayLimit: 20 }), { a: [{ b: [{ c: '1' }] }] });
267
+ st.deepEqual(qs.parse('a[1][2][3][c]=1', { arrayLimit: 20 }), { a: [[[{ c: '1' }]]] });
268
+ st.deepEqual(qs.parse('a[1][2][3][c][1]=1', { arrayLimit: 20 }), { a: [[[{ c: ['1'] }]]] });
269
+ st.end();
270
+ });
271
+
272
+ t.test('parses semi-parsed strings', function (st) {
273
+ st.deepEqual(qs.parse({ 'a[b]': 'c' }), { a: { b: 'c' } });
274
+ st.deepEqual(qs.parse({ 'a[b]': 'c', 'a[d]': 'e' }), { a: { b: 'c', d: 'e' } });
275
+ st.end();
276
+ });
277
+
278
+ t.test('parses buffers correctly', function (st) {
279
+ var b = SaferBuffer.from('test');
280
+ st.deepEqual(qs.parse({ a: b }), { a: b });
281
+ st.end();
282
+ });
283
+
284
+ t.test('parses jquery-param strings', function (st) {
285
+ // readable = 'filter[0][]=int1&filter[0][]==&filter[0][]=77&filter[]=and&filter[2][]=int2&filter[2][]==&filter[2][]=8'
286
+ var encoded = 'filter%5B0%5D%5B%5D=int1&filter%5B0%5D%5B%5D=%3D&filter%5B0%5D%5B%5D=77&filter%5B%5D=and&filter%5B2%5D%5B%5D=int2&filter%5B2%5D%5B%5D=%3D&filter%5B2%5D%5B%5D=8';
287
+ var expected = { filter: [['int1', '=', '77'], 'and', ['int2', '=', '8']] };
288
+ st.deepEqual(qs.parse(encoded), expected);
289
+ st.end();
290
+ });
291
+
292
+ t.test('continues parsing when no parent is found', function (st) {
293
+ st.deepEqual(qs.parse('[]=&a=b'), { 0: '', a: 'b' });
294
+ st.deepEqual(qs.parse('[]&a=b', { strictNullHandling: true }), { 0: null, a: 'b' });
295
+ st.deepEqual(qs.parse('[foo]=bar'), { foo: 'bar' });
296
+ st.end();
297
+ });
298
+
299
+ t.test('does not error when parsing a very long array', function (st) {
300
+ var str = 'a[]=a';
301
+ while (Buffer.byteLength(str) < 128 * 1024) {
302
+ str = str + '&' + str;
303
+ }
304
+
305
+ st.doesNotThrow(function () {
306
+ qs.parse(str);
307
+ });
308
+
309
+ st.end();
310
+ });
311
+
312
+ t.test('should not throw when a native prototype has an enumerable property', function (st) {
313
+ Object.prototype.crash = '';
314
+ Array.prototype.crash = '';
315
+ st.doesNotThrow(qs.parse.bind(null, 'a=b'));
316
+ st.deepEqual(qs.parse('a=b'), { a: 'b' });
317
+ st.doesNotThrow(qs.parse.bind(null, 'a[][b]=c'));
318
+ st.deepEqual(qs.parse('a[][b]=c'), { a: [{ b: 'c' }] });
319
+ delete Object.prototype.crash;
320
+ delete Array.prototype.crash;
321
+ st.end();
322
+ });
323
+
324
+ t.test('parses a string with an alternative string delimiter', function (st) {
325
+ st.deepEqual(qs.parse('a=b;c=d', { delimiter: ';' }), { a: 'b', c: 'd' });
326
+ st.end();
327
+ });
328
+
329
+ t.test('parses a string with an alternative RegExp delimiter', function (st) {
330
+ st.deepEqual(qs.parse('a=b; c=d', { delimiter: /[;,] */ }), { a: 'b', c: 'd' });
331
+ st.end();
332
+ });
333
+
334
+ t.test('does not use non-splittable objects as delimiters', function (st) {
335
+ st.deepEqual(qs.parse('a=b&c=d', { delimiter: true }), { a: 'b', c: 'd' });
336
+ st.end();
337
+ });
338
+
339
+ t.test('allows overriding parameter limit', function (st) {
340
+ st.deepEqual(qs.parse('a=b&c=d', { parameterLimit: 1 }), { a: 'b' });
341
+ st.end();
342
+ });
343
+
344
+ t.test('allows setting the parameter limit to Infinity', function (st) {
345
+ st.deepEqual(qs.parse('a=b&c=d', { parameterLimit: Infinity }), { a: 'b', c: 'd' });
346
+ st.end();
347
+ });
348
+
349
+ t.test('allows overriding array limit', function (st) {
350
+ st.deepEqual(qs.parse('a[0]=b', { arrayLimit: -1 }), { a: { 0: 'b' } });
351
+ st.deepEqual(qs.parse('a[-1]=b', { arrayLimit: -1 }), { a: { '-1': 'b' } });
352
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayLimit: 0 }), { a: { 0: 'b', 1: 'c' } });
353
+ st.end();
354
+ });
355
+
356
+ t.test('allows disabling array parsing', function (st) {
357
+ var indices = qs.parse('a[0]=b&a[1]=c', { parseArrays: false });
358
+ st.deepEqual(indices, { a: { 0: 'b', 1: 'c' } });
359
+ st.equal(Array.isArray(indices.a), false, 'parseArrays:false, indices case is not an array');
360
+
361
+ var emptyBrackets = qs.parse('a[]=b', { parseArrays: false });
362
+ st.deepEqual(emptyBrackets, { a: { 0: 'b' } });
363
+ st.equal(Array.isArray(emptyBrackets.a), false, 'parseArrays:false, empty brackets case is not an array');
364
+
365
+ st.end();
366
+ });
367
+
368
+ t.test('allows for query string prefix', function (st) {
369
+ st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
370
+ st.deepEqual(qs.parse('foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
371
+ st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: false }), { '?foo': 'bar' });
372
+ st.end();
373
+ });
374
+
375
+ t.test('parses an object', function (st) {
376
+ var input = {
377
+ 'user[name]': { 'pop[bob]': 3 },
378
+ 'user[email]': null
379
+ };
380
+
381
+ var expected = {
382
+ user: {
383
+ name: { 'pop[bob]': 3 },
384
+ email: null
385
+ }
386
+ };
387
+
388
+ var result = qs.parse(input);
389
+
390
+ st.deepEqual(result, expected);
391
+ st.end();
392
+ });
393
+
394
+ t.test('parses string with comma as array divider', function (st) {
395
+ st.deepEqual(qs.parse('foo=bar,tee', { comma: true }), { foo: ['bar', 'tee'] });
396
+ st.deepEqual(qs.parse('foo[bar]=coffee,tee', { comma: true }), { foo: { bar: ['coffee', 'tee'] } });
397
+ st.deepEqual(qs.parse('foo=', { comma: true }), { foo: '' });
398
+ st.deepEqual(qs.parse('foo', { comma: true }), { foo: '' });
399
+ st.deepEqual(qs.parse('foo', { comma: true, strictNullHandling: true }), { foo: null });
400
+ st.end();
401
+ });
402
+
403
+ t.test('parses values with comma as array divider', function (st) {
404
+ st.deepEqual(qs.parse({ foo: 'bar,tee' }, { comma: false }), { foo: 'bar,tee' });
405
+ st.deepEqual(qs.parse({ foo: 'bar,tee' }, { comma: true }), { foo: ['bar', 'tee'] });
406
+ st.end();
407
+ });
408
+
409
+ t.test('use number decoder, parses string that has one number with comma option enabled', function (st) {
410
+ var decoder = function (str, defaultDecoder, charset, type) {
411
+ if (!isNaN(Number(str))) {
412
+ return parseFloat(str);
413
+ }
414
+ return defaultDecoder(str, defaultDecoder, charset, type);
415
+ };
416
+
417
+ st.deepEqual(qs.parse('foo=1', { comma: true, decoder: decoder }), { foo: 1 });
418
+ st.deepEqual(qs.parse('foo=0', { comma: true, decoder: decoder }), { foo: 0 });
419
+
420
+ st.end();
421
+ });
422
+
423
+ t.test('parses brackets holds array of arrays when having two parts of strings with comma as array divider', function (st) {
424
+ st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=4,5,6', { comma: true }), { foo: [['1', '2', '3'], ['4', '5', '6']] });
425
+ st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=', { comma: true }), { foo: [['1', '2', '3'], ''] });
426
+ st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=,', { comma: true }), { foo: [['1', '2', '3'], ['', '']] });
427
+ st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=a', { comma: true }), { foo: [['1', '2', '3'], 'a'] });
428
+
429
+ st.end();
430
+ });
431
+
432
+ t.test('parses comma delimited array while having percent-encoded comma treated as normal text', function (st) {
433
+ st.deepEqual(qs.parse('foo=a%2Cb', { comma: true }), { foo: 'a,b' });
434
+ st.deepEqual(qs.parse('foo=a%2C%20b,d', { comma: true }), { foo: ['a, b', 'd'] });
435
+ st.deepEqual(qs.parse('foo=a%2C%20b,c%2C%20d', { comma: true }), { foo: ['a, b', 'c, d'] });
436
+
437
+ st.end();
438
+ });
439
+
440
+ t.test('parses an object in dot notation', function (st) {
441
+ var input = {
442
+ 'user.name': { 'pop[bob]': 3 },
443
+ 'user.email.': null
444
+ };
445
+
446
+ var expected = {
447
+ user: {
448
+ name: { 'pop[bob]': 3 },
449
+ email: null
450
+ }
451
+ };
452
+
453
+ var result = qs.parse(input, { allowDots: true });
454
+
455
+ st.deepEqual(result, expected);
456
+ st.end();
457
+ });
458
+
459
+ t.test('parses an object and not child values', function (st) {
460
+ var input = {
461
+ 'user[name]': { 'pop[bob]': { test: 3 } },
462
+ 'user[email]': null
463
+ };
464
+
465
+ var expected = {
466
+ user: {
467
+ name: { 'pop[bob]': { test: 3 } },
468
+ email: null
469
+ }
470
+ };
471
+
472
+ var result = qs.parse(input);
473
+
474
+ st.deepEqual(result, expected);
475
+ st.end();
476
+ });
477
+
478
+ t.test('does not blow up when Buffer global is missing', function (st) {
479
+ var tempBuffer = global.Buffer;
480
+ delete global.Buffer;
481
+ var result = qs.parse('a=b&c=d');
482
+ global.Buffer = tempBuffer;
483
+ st.deepEqual(result, { a: 'b', c: 'd' });
484
+ st.end();
485
+ });
486
+
487
+ t.test('does not crash when parsing circular references', function (st) {
488
+ var a = {};
489
+ a.b = a;
490
+
491
+ var parsed;
492
+
493
+ st.doesNotThrow(function () {
494
+ parsed = qs.parse({ 'foo[bar]': 'baz', 'foo[baz]': a });
495
+ });
496
+
497
+ st.equal('foo' in parsed, true, 'parsed has "foo" property');
498
+ st.equal('bar' in parsed.foo, true);
499
+ st.equal('baz' in parsed.foo, true);
500
+ st.equal(parsed.foo.bar, 'baz');
501
+ st.deepEqual(parsed.foo.baz, a);
502
+ st.end();
503
+ });
504
+
505
+ t.test('does not crash when parsing deep objects', function (st) {
506
+ var parsed;
507
+ var str = 'foo';
508
+
509
+ for (var i = 0; i < 5000; i++) {
510
+ str += '[p]';
511
+ }
512
+
513
+ str += '=bar';
514
+
515
+ st.doesNotThrow(function () {
516
+ parsed = qs.parse(str, { depth: 5000 });
517
+ });
518
+
519
+ st.equal('foo' in parsed, true, 'parsed has "foo" property');
520
+
521
+ var depth = 0;
522
+ var ref = parsed.foo;
523
+ while ((ref = ref.p)) {
524
+ depth += 1;
525
+ }
526
+
527
+ st.equal(depth, 5000, 'parsed is 5000 properties deep');
528
+
529
+ st.end();
530
+ });
531
+
532
+ t.test('parses null objects correctly', { skip: !Object.create }, function (st) {
533
+ var a = Object.create(null);
534
+ a.b = 'c';
535
+
536
+ st.deepEqual(qs.parse(a), { b: 'c' });
537
+ var result = qs.parse({ a: a });
538
+ st.equal('a' in result, true, 'result has "a" property');
539
+ st.deepEqual(result.a, a);
540
+ st.end();
541
+ });
542
+
543
+ t.test('parses dates correctly', function (st) {
544
+ var now = new Date();
545
+ st.deepEqual(qs.parse({ a: now }), { a: now });
546
+ st.end();
547
+ });
548
+
549
+ t.test('parses regular expressions correctly', function (st) {
550
+ var re = /^test$/;
551
+ st.deepEqual(qs.parse({ a: re }), { a: re });
552
+ st.end();
553
+ });
554
+
555
+ t.test('does not allow overwriting prototype properties', function (st) {
556
+ st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: false }), {});
557
+ st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: false }), {});
558
+
559
+ st.deepEqual(
560
+ qs.parse('toString', { allowPrototypes: false }),
561
+ {},
562
+ 'bare "toString" results in {}'
563
+ );
564
+
565
+ st.end();
566
+ });
567
+
568
+ t.test('can allow overwriting prototype properties', function (st) {
569
+ st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true }), { a: { hasOwnProperty: 'b' } });
570
+ st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: true }), { hasOwnProperty: 'b' });
571
+
572
+ st.deepEqual(
573
+ qs.parse('toString', { allowPrototypes: true }),
574
+ { toString: '' },
575
+ 'bare "toString" results in { toString: "" }'
576
+ );
577
+
578
+ st.end();
579
+ });
580
+
581
+ t.test('params starting with a closing bracket', function (st) {
582
+ st.deepEqual(qs.parse(']=toString'), { ']': 'toString' });
583
+ st.deepEqual(qs.parse(']]=toString'), { ']]': 'toString' });
584
+ st.deepEqual(qs.parse(']hello]=toString'), { ']hello]': 'toString' });
585
+ st.end();
586
+ });
587
+
588
+ t.test('params starting with a starting bracket', function (st) {
589
+ st.deepEqual(qs.parse('[=toString'), { '[': 'toString' });
590
+ st.deepEqual(qs.parse('[[=toString'), { '[[': 'toString' });
591
+ st.deepEqual(qs.parse('[hello[=toString'), { '[hello[': 'toString' });
592
+ st.end();
593
+ });
594
+
595
+ t.test('add keys to objects', function (st) {
596
+ st.deepEqual(
597
+ qs.parse('a[b]=c&a=d'),
598
+ { a: { b: 'c', d: true } },
599
+ 'can add keys to objects'
600
+ );
601
+
602
+ st.deepEqual(
603
+ qs.parse('a[b]=c&a=toString'),
604
+ { a: { b: 'c' } },
605
+ 'can not overwrite prototype'
606
+ );
607
+
608
+ st.deepEqual(
609
+ qs.parse('a[b]=c&a=toString', { allowPrototypes: true }),
610
+ { a: { b: 'c', toString: true } },
611
+ 'can overwrite prototype with allowPrototypes true'
612
+ );
613
+
614
+ st.deepEqual(
615
+ qs.parse('a[b]=c&a=toString', { plainObjects: true }),
616
+ { __proto__: null, a: { __proto__: null, b: 'c', toString: true } },
617
+ 'can overwrite prototype with plainObjects true'
618
+ );
619
+
620
+ st.end();
621
+ });
622
+
623
+ t.test('can return null objects', { skip: !Object.create }, function (st) {
624
+ var expected = Object.create(null);
625
+ expected.a = Object.create(null);
626
+ expected.a.b = 'c';
627
+ expected.a.hasOwnProperty = 'd';
628
+ st.deepEqual(qs.parse('a[b]=c&a[hasOwnProperty]=d', { plainObjects: true }), expected);
629
+ st.deepEqual(qs.parse(null, { plainObjects: true }), Object.create(null));
630
+ var expectedArray = Object.create(null);
631
+ expectedArray.a = Object.create(null);
632
+ expectedArray.a[0] = 'b';
633
+ expectedArray.a.c = 'd';
634
+ st.deepEqual(qs.parse('a[]=b&a[c]=d', { plainObjects: true }), expectedArray);
635
+ st.end();
636
+ });
637
+
638
+ t.test('can parse with custom encoding', function (st) {
639
+ st.deepEqual(qs.parse('%8c%a7=%91%e5%8d%e3%95%7b', {
640
+ decoder: function (str) {
641
+ var reg = /%([0-9A-F]{2})/ig;
642
+ var result = [];
643
+ var parts = reg.exec(str);
644
+ while (parts) {
645
+ result.push(parseInt(parts[1], 16));
646
+ parts = reg.exec(str);
647
+ }
648
+ return String(iconv.decode(SaferBuffer.from(result), 'shift_jis'));
649
+ }
650
+ }), { 県: '大阪府' });
651
+ st.end();
652
+ });
653
+
654
+ t.test('receives the default decoder as a second argument', function (st) {
655
+ st.plan(1);
656
+ qs.parse('a', {
657
+ decoder: function (str, defaultDecoder) {
658
+ st.equal(defaultDecoder, utils.decode);
659
+ }
660
+ });
661
+ st.end();
662
+ });
663
+
664
+ t.test('throws error with wrong decoder', function (st) {
665
+ st['throws'](function () {
666
+ qs.parse({}, { decoder: 'string' });
667
+ }, new TypeError('Decoder has to be a function.'));
668
+ st.end();
669
+ });
670
+
671
+ t.test('does not mutate the options argument', function (st) {
672
+ var options = {};
673
+ qs.parse('a[b]=true', options);
674
+ st.deepEqual(options, {});
675
+ st.end();
676
+ });
677
+
678
+ t.test('throws if an invalid charset is specified', function (st) {
679
+ st['throws'](function () {
680
+ qs.parse('a=b', { charset: 'foobar' });
681
+ }, new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'));
682
+ st.end();
683
+ });
684
+
685
+ t.test('parses an iso-8859-1 string if asked to', function (st) {
686
+ st.deepEqual(qs.parse('%A2=%BD', { charset: 'iso-8859-1' }), { '¢': '½' });
687
+ st.end();
688
+ });
689
+
690
+ var urlEncodedCheckmarkInUtf8 = '%E2%9C%93';
691
+ var urlEncodedOSlashInUtf8 = '%C3%B8';
692
+ var urlEncodedNumCheckmark = '%26%2310003%3B';
693
+ var urlEncodedNumSmiley = '%26%239786%3B';
694
+
695
+ t.test('prefers an utf-8 charset specified by the utf8 sentinel to a default charset of iso-8859-1', function (st) {
696
+ st.deepEqual(qs.parse('utf8=' + urlEncodedCheckmarkInUtf8 + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { charsetSentinel: true, charset: 'iso-8859-1' }), { ø: 'ø' });
697
+ st.end();
698
+ });
699
+
700
+ t.test('prefers an iso-8859-1 charset specified by the utf8 sentinel to a default charset of utf-8', function (st) {
701
+ st.deepEqual(qs.parse('utf8=' + urlEncodedNumCheckmark + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { charsetSentinel: true, charset: 'utf-8' }), { 'ø': 'ø' });
702
+ st.end();
703
+ });
704
+
705
+ t.test('does not require the utf8 sentinel to be defined before the parameters whose decoding it affects', function (st) {
706
+ st.deepEqual(qs.parse('a=' + urlEncodedOSlashInUtf8 + '&utf8=' + urlEncodedNumCheckmark, { charsetSentinel: true, charset: 'utf-8' }), { a: 'ø' });
707
+ st.end();
708
+ });
709
+
710
+ t.test('should ignore an utf8 sentinel with an unknown value', function (st) {
711
+ st.deepEqual(qs.parse('utf8=foo&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { charsetSentinel: true, charset: 'utf-8' }), { ø: 'ø' });
712
+ st.end();
713
+ });
714
+
715
+ t.test('uses the utf8 sentinel to switch to utf-8 when no default charset is given', function (st) {
716
+ st.deepEqual(qs.parse('utf8=' + urlEncodedCheckmarkInUtf8 + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { charsetSentinel: true }), { ø: 'ø' });
717
+ st.end();
718
+ });
719
+
720
+ t.test('uses the utf8 sentinel to switch to iso-8859-1 when no default charset is given', function (st) {
721
+ st.deepEqual(qs.parse('utf8=' + urlEncodedNumCheckmark + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { charsetSentinel: true }), { 'ø': 'ø' });
722
+ st.end();
723
+ });
724
+
725
+ t.test('interprets numeric entities in iso-8859-1 when `interpretNumericEntities`', function (st) {
726
+ st.deepEqual(qs.parse('foo=' + urlEncodedNumSmiley, { charset: 'iso-8859-1', interpretNumericEntities: true }), { foo: '☺' });
727
+ st.end();
728
+ });
729
+
730
+ t.test('handles a custom decoder returning `null`, in the `iso-8859-1` charset, when `interpretNumericEntities`', function (st) {
731
+ st.deepEqual(qs.parse('foo=&bar=' + urlEncodedNumSmiley, {
732
+ charset: 'iso-8859-1',
733
+ decoder: function (str, defaultDecoder, charset) {
734
+ return str ? defaultDecoder(str, defaultDecoder, charset) : null;
735
+ },
736
+ interpretNumericEntities: true
737
+ }), { foo: null, bar: '☺' });
738
+ st.end();
739
+ });
740
+
741
+ t.test('does not interpret numeric entities in iso-8859-1 when `interpretNumericEntities` is absent', function (st) {
742
+ st.deepEqual(qs.parse('foo=' + urlEncodedNumSmiley, { charset: 'iso-8859-1' }), { foo: '&#9786;' });
743
+ st.end();
744
+ });
745
+
746
+ t.test('does not interpret numeric entities when the charset is utf-8, even when `interpretNumericEntities`', function (st) {
747
+ st.deepEqual(qs.parse('foo=' + urlEncodedNumSmiley, { charset: 'utf-8', interpretNumericEntities: true }), { foo: '&#9786;' });
748
+ st.end();
749
+ });
750
+
751
+ t.test('does not interpret %uXXXX syntax in iso-8859-1 mode', function (st) {
752
+ st.deepEqual(qs.parse('%u263A=%u263A', { charset: 'iso-8859-1' }), { '%u263A': '%u263A' });
753
+ st.end();
754
+ });
755
+
756
+ t.test('allows for decoding keys and values differently', function (st) {
757
+ var decoder = function (str, defaultDecoder, charset, type) {
758
+ if (type === 'key') {
759
+ return defaultDecoder(str, defaultDecoder, charset, type).toLowerCase();
760
+ }
761
+ if (type === 'value') {
762
+ return defaultDecoder(str, defaultDecoder, charset, type).toUpperCase();
763
+ }
764
+ throw 'this should never happen! type: ' + type;
765
+ };
766
+
767
+ st.deepEqual(qs.parse('KeY=vAlUe', { decoder: decoder }), { key: 'VALUE' });
768
+ st.end();
769
+ });
770
+
771
+ t.end();
772
+ });