querystring: lazy loaded

PR-URL: https://github.com/nodejs/node/pull/20567
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
Ruben Bridgewater 2018-05-06 23:08:42 +02:00
parent f4f8b22f7d
commit d0bb9b1205
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 14 additions and 4 deletions

View File

@ -27,7 +27,9 @@ const {
CHAR_LOWERCASE_A,
CHAR_LOWERCASE_Z,
} = require('internal/constants');
const querystring = require('querystring');
// Lazy loaded for startup performance.
let querystring;
const { platform } = process;
const isWindows = platform === 'win32';
@ -771,8 +773,10 @@ function parseParams(qs) {
} else if (encodeCheck > 0) {
// eslint-disable-next-line no-extra-boolean-cast
if (!!isHexTable[code]) {
if (++encodeCheck === 3)
if (++encodeCheck === 3) {
querystring = require('querystring');
encoded = true;
}
} else {
encodeCheck = 0;
}

View File

@ -94,7 +94,6 @@ const slashedProtocol = {
'file': true,
'file:': true
};
const querystring = require('querystring');
const {
CHAR_SPACE,
CHAR_TAB,
@ -133,6 +132,9 @@ const {
CHAR_AT,
} = require('internal/constants');
// Lazy loaded for startup performance.
let querystring;
function urlParse(url, parseQueryString, slashesDenoteHost) {
if (url instanceof Url) return url;
@ -233,6 +235,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
if (simplePath[2]) {
this.search = simplePath[2];
if (parseQueryString) {
if (querystring === undefined) querystring = require('querystring');
this.query = querystring.parse(this.search.slice(1));
} else {
this.query = this.search.slice(1);
@ -422,6 +425,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
this.query = rest.slice(questionIdx + 1, hashIdx);
}
if (parseQueryString) {
if (querystring === undefined) querystring = require('querystring');
this.query = querystring.parse(this.query);
}
} else if (parseQueryString) {
@ -584,8 +588,10 @@ Url.prototype.format = function format() {
}
}
if (this.query !== null && typeof this.query === 'object')
if (this.query !== null && typeof this.query === 'object') {
if (querystring === undefined) querystring = require('querystring');
query = querystring.stringify(this.query);
}
var search = this.search || (query && ('?' + query)) || '';