diff options
author | isaacs <i@izs.me> | 2019-07-24 23:00:03 -0700 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2019-08-06 09:05:32 +0200 |
commit | d7d321b071789f08c65dbb11a0e4b3b6a299af44 (patch) | |
tree | 1015b8c5da3632fc986b56051a4853ac946c56f4 /deps/npm/node_modules/query-string/index.js | |
parent | 37d27486fce50bd82b6b5095af880d435ed308f8 (diff) | |
download | android-node-v8-d7d321b071789f08c65dbb11a0e4b3b6a299af44.tar.gz android-node-v8-d7d321b071789f08c65dbb11a0e4b3b6a299af44.tar.bz2 android-node-v8-d7d321b071789f08c65dbb11a0e4b3b6a299af44.zip |
deps: upgrade npm to 6.10.2
PR-URL: https://github.com/nodejs/node/pull/28853
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Diffstat (limited to 'deps/npm/node_modules/query-string/index.js')
-rw-r--r-- | deps/npm/node_modules/query-string/index.js | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/deps/npm/node_modules/query-string/index.js b/deps/npm/node_modules/query-string/index.js index 3cb1adf8d3..da459c9404 100644 --- a/deps/npm/node_modules/query-string/index.js +++ b/deps/npm/node_modules/query-string/index.js @@ -1,6 +1,7 @@ 'use strict'; const strictUriEncode = require('strict-uri-encode'); const decodeComponent = require('decode-uri-component'); +const splitOnFirst = require('split-on-first'); function encoderForArrayFormat(options) { switch (options.arrayFormat) { @@ -36,7 +37,7 @@ function encoderForArrayFormat(options) { case 'comma': return key => (result, value, index) => { - if (!value) { + if (value === null || value === undefined || value.length === 0) { return result; } @@ -151,7 +152,17 @@ function keysSorter(input) { return input; } +function removeHash(input) { + const hashStart = input.indexOf('#'); + if (hashStart !== -1) { + input = input.slice(0, hashStart); + } + + return input; +} + function extract(input) { + input = removeHash(input); const queryStart = input.indexOf('?'); if (queryStart === -1) { return ''; @@ -163,7 +174,10 @@ function extract(input) { function parse(input, options) { options = Object.assign({ decode: true, - arrayFormat: 'none' + sort: true, + arrayFormat: 'none', + parseNumbers: false, + parseBooleans: false }, options); const formatter = parserForArrayFormat(options); @@ -182,16 +196,26 @@ function parse(input, options) { } for (const param of input.split('&')) { - let [key, value] = param.replace(/\+/g, ' ').split('='); + let [key, value] = splitOnFirst(param.replace(/\+/g, ' '), '='); // Missing `=` should be `null`: // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters value = value === undefined ? null : decode(value, options); + if (options.parseNumbers && !Number.isNaN(Number(value))) { + value = Number(value); + } else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) { + value = value.toLowerCase() === 'true'; + } + formatter(decode(key, options), value, ret); } - return Object.keys(ret).sort().reduce((result, key) => { + if (options.sort === false) { + return ret; + } + + return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => { const value = ret[key]; if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) { // Sort object keys, not values @@ -247,13 +271,8 @@ exports.stringify = (object, options) => { }; exports.parseUrl = (input, options) => { - const hashStart = input.indexOf('#'); - if (hashStart !== -1) { - input = input.slice(0, hashStart); - } - return { - url: input.split('?')[0] || '', + url: removeHash(input).split('?')[0] || '', query: parse(extract(input), options) }; }; |