url: replace "magic" numbers by constants
PR-URL: https://github.com/nodejs/node/pull/19300 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit is contained in:
parent
422ac61535
commit
354849eeb5
@ -39,6 +39,8 @@ module.exports = {
|
|||||||
CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
|
CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
|
||||||
CHAR_GRAVE_ACCENT: 96, /* ` */
|
CHAR_GRAVE_ACCENT: 96, /* ` */
|
||||||
CHAR_AT: 64, /* @ */
|
CHAR_AT: 64, /* @ */
|
||||||
|
CHAR_AMPERSAND: 38, /* & */
|
||||||
|
CHAR_EQUAL: 61, /* = */
|
||||||
|
|
||||||
// Digits
|
// Digits
|
||||||
CHAR_0: 48, /* 0 */
|
CHAR_0: 48, /* 0 */
|
||||||
|
@ -19,6 +19,14 @@ const {
|
|||||||
ERR_INVALID_URL_SCHEME,
|
ERR_INVALID_URL_SCHEME,
|
||||||
ERR_MISSING_ARGS
|
ERR_MISSING_ARGS
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
|
const {
|
||||||
|
CHAR_PERCENT,
|
||||||
|
CHAR_PLUS,
|
||||||
|
CHAR_AMPERSAND,
|
||||||
|
CHAR_EQUAL,
|
||||||
|
CHAR_LOWERCASE_A,
|
||||||
|
CHAR_LOWERCASE_Z,
|
||||||
|
} = require('internal/constants');
|
||||||
const querystring = require('querystring');
|
const querystring = require('querystring');
|
||||||
|
|
||||||
const { platform } = process;
|
const { platform } = process;
|
||||||
@ -712,7 +720,7 @@ function parseParams(qs) {
|
|||||||
const code = qs.charCodeAt(i);
|
const code = qs.charCodeAt(i);
|
||||||
|
|
||||||
// Try matching key/value pair separator
|
// Try matching key/value pair separator
|
||||||
if (code === 38/* & */) {
|
if (code === CHAR_AMPERSAND) {
|
||||||
if (pairStart === i) {
|
if (pairStart === i) {
|
||||||
// We saw an empty substring between pair separators
|
// We saw an empty substring between pair separators
|
||||||
lastPos = pairStart = i + 1;
|
lastPos = pairStart = i + 1;
|
||||||
@ -738,7 +746,7 @@ function parseParams(qs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try matching key/value separator (e.g. '=') if we haven't already
|
// Try matching key/value separator (e.g. '=') if we haven't already
|
||||||
if (!seenSep && code === 61/* = */) {
|
if (!seenSep && code === CHAR_EQUAL) {
|
||||||
// Key/value separator match!
|
// Key/value separator match!
|
||||||
if (lastPos < i)
|
if (lastPos < i)
|
||||||
buf += qs.slice(lastPos, i);
|
buf += qs.slice(lastPos, i);
|
||||||
@ -755,7 +763,7 @@ function parseParams(qs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle + and percent decoding.
|
// Handle + and percent decoding.
|
||||||
if (code === 43/* + */) {
|
if (code === CHAR_PLUS) {
|
||||||
if (lastPos < i)
|
if (lastPos < i)
|
||||||
buf += qs.slice(lastPos, i);
|
buf += qs.slice(lastPos, i);
|
||||||
buf += ' ';
|
buf += ' ';
|
||||||
@ -763,7 +771,7 @@ function parseParams(qs) {
|
|||||||
} else if (!encoded) {
|
} else if (!encoded) {
|
||||||
// Try to match an (valid) encoded byte (once) to minimize unnecessary
|
// Try to match an (valid) encoded byte (once) to minimize unnecessary
|
||||||
// calls to string decoding functions
|
// calls to string decoding functions
|
||||||
if (code === 37/* % */) {
|
if (code === CHAR_PERCENT) {
|
||||||
encodeCheck = 1;
|
encodeCheck = 1;
|
||||||
} else if (encodeCheck > 0) {
|
} else if (encodeCheck > 0) {
|
||||||
// eslint-disable-next-line no-extra-boolean-cast
|
// eslint-disable-next-line no-extra-boolean-cast
|
||||||
@ -1357,7 +1365,7 @@ function getPathFromURLWin32(url) {
|
|||||||
// Otherwise, it's a local path that requires a drive letter
|
// Otherwise, it's a local path that requires a drive letter
|
||||||
var letter = pathname.codePointAt(1) | 0x20;
|
var letter = pathname.codePointAt(1) | 0x20;
|
||||||
var sep = pathname[2];
|
var sep = pathname[2];
|
||||||
if (letter < 97 || letter > 122 || // a..z A..Z
|
if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || // a..z A..Z
|
||||||
(sep !== ':')) {
|
(sep !== ':')) {
|
||||||
throw new ERR_INVALID_FILE_URL_PATH('must be absolute');
|
throw new ERR_INVALID_FILE_URL_PATH('must be absolute');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user