-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
url: replace var with let in lib/url.js #30281
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,13 +157,13 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
// Copy chrome, IE, opera backslash-handling behavior. | ||
// Back slashes before the query string get converted to forward slashes | ||
// See: https://code.google.com/p/chromium/issues/detail?id=25916 | ||
var hasHash = false; | ||
var start = -1; | ||
var end = -1; | ||
var rest = ''; | ||
var lastPos = 0; | ||
var i = 0; | ||
for (var inWs = false, split = false; i < url.length; ++i) { | ||
let hasHash = false; | ||
let start = -1; | ||
let end = -1; | ||
let rest = ''; | ||
let lastPos = 0; | ||
let i = 0; | ||
for (let inWs = false, split = false; i < url.length; ++i) { | ||
const code = url.charCodeAt(i); | ||
|
||
// Find first and last non-whitespace characters for trimming | ||
|
@@ -292,9 +292,9 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
// http://a@b@c/ => user:a@b host:c | ||
// http://a@b?@c => user:a host:b path:/?@c | ||
|
||
var hostEnd = -1; | ||
var atSign = -1; | ||
var nonHost = -1; | ||
let hostEnd = -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the variable |
||
let atSign = -1; | ||
let nonHost = -1; | ||
for (i = 0; i < rest.length; ++i) { | ||
switch (rest.charCodeAt(i)) { | ||
case CHAR_TAB: | ||
|
@@ -356,11 +356,11 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
if (typeof this.hostname !== 'string') | ||
this.hostname = ''; | ||
|
||
var hostname = this.hostname; | ||
const hostname = this.hostname; | ||
|
||
// If hostname begins with [ and ends with ] | ||
// assume that it's an IPv6 address. | ||
var ipv6Hostname = hostname.charCodeAt(0) === CHAR_LEFT_SQUARE_BRACKET && | ||
const ipv6Hostname = hostname.charCodeAt(0) === CHAR_LEFT_SQUARE_BRACKET && | ||
hostname.charCodeAt(hostname.length - 1) === CHAR_RIGHT_SQUARE_BRACKET; | ||
|
||
// validate a little. | ||
|
@@ -386,8 +386,8 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
this.hostname = toASCII(this.hostname, true); | ||
} | ||
|
||
var p = this.port ? ':' + this.port : ''; | ||
var h = this.hostname || ''; | ||
const p = this.port ? ':' + this.port : ''; | ||
const h = this.hostname || ''; | ||
this.host = h + p; | ||
|
||
// strip [ and ] from the hostname | ||
|
@@ -409,8 +409,8 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
rest = autoEscapeStr(rest); | ||
} | ||
|
||
var questionIdx = -1; | ||
var hashIdx = -1; | ||
let questionIdx = -1; | ||
let hashIdx = -1; | ||
for (i = 0; i < rest.length; ++i) { | ||
const code = rest.charCodeAt(i); | ||
if (code === CHAR_HASH) { | ||
|
@@ -467,7 +467,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
}; | ||
|
||
function getHostname(self, rest, hostname) { | ||
for (var i = 0; i < hostname.length; ++i) { | ||
for (let i = 0; i < hostname.length; ++i) { | ||
const code = hostname.charCodeAt(i); | ||
const isValid = (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) || | ||
code === CHAR_DOT || | ||
|
@@ -509,11 +509,11 @@ const escapedCodes = [ | |
// Also escape single quotes in case of an XSS attack. | ||
// Return the escaped string. | ||
function autoEscapeStr(rest) { | ||
var escaped = ''; | ||
var lastEscapedPos = 0; | ||
for (var i = 0; i < rest.length; ++i) { | ||
let escaped = ''; | ||
let lastEscapedPos = 0; | ||
for (let i = 0; i < rest.length; ++i) { | ||
// `escaped` contains substring up to the last escaped character. | ||
var escapedChar = escapedCodes[rest.charCodeAt(i)]; | ||
const escapedChar = escapedCodes[rest.charCodeAt(i)]; | ||
if (escapedChar) { | ||
// Concat if there are ordinary characters in the middle. | ||
if (i > lastEscapedPos) | ||
|
@@ -544,7 +544,7 @@ function urlFormat(urlObject, options) { | |
throw new ERR_INVALID_ARG_TYPE('urlObject', | ||
['Object', 'string'], urlObject); | ||
} else if (!(urlObject instanceof Url)) { | ||
var format = urlObject[formatSymbol]; | ||
const format = urlObject[formatSymbol]; | ||
return format ? | ||
format.call(urlObject, options) : | ||
Url.prototype.format.call(urlObject); | ||
|
@@ -570,17 +570,17 @@ const noEscapeAuth = [ | |
]; | ||
|
||
Url.prototype.format = function format() { | ||
var auth = this.auth || ''; | ||
let auth = this.auth || ''; | ||
if (auth) { | ||
auth = encodeStr(auth, noEscapeAuth, hexTable); | ||
auth += '@'; | ||
} | ||
|
||
var protocol = this.protocol || ''; | ||
var pathname = this.pathname || ''; | ||
var hash = this.hash || ''; | ||
var host = ''; | ||
var query = ''; | ||
let protocol = this.protocol || ''; | ||
let pathname = this.pathname || ''; | ||
let hash = this.hash || ''; | ||
let host = ''; | ||
let query = ''; | ||
|
||
if (this.host) { | ||
host = auth + this.host; | ||
|
@@ -600,14 +600,14 @@ Url.prototype.format = function format() { | |
query = querystring.stringify(this.query); | ||
} | ||
|
||
var search = this.search || (query && ('?' + query)) || ''; | ||
let search = this.search || (query && ('?' + query)) || ''; | ||
|
||
if (protocol && protocol.charCodeAt(protocol.length - 1) !== 58/* : */) | ||
protocol += ':'; | ||
|
||
var newPathname = ''; | ||
var lastPos = 0; | ||
for (var i = 0; i < pathname.length; ++i) { | ||
let newPathname = ''; | ||
let lastPos = 0; | ||
for (let i = 0; i < pathname.length; ++i) { | ||
switch (pathname.charCodeAt(i)) { | ||
case CHAR_HASH: | ||
if (i - lastPos > 0) | ||
|
@@ -671,15 +671,15 @@ function urlResolveObject(source, relative) { | |
|
||
Url.prototype.resolveObject = function resolveObject(relative) { | ||
if (typeof relative === 'string') { | ||
var rel = new Url(); | ||
const rel = new Url(); | ||
rel.parse(relative, false, true); | ||
relative = rel; | ||
} | ||
|
||
const result = new Url(); | ||
const tkeys = Object.keys(this); | ||
for (var tk = 0; tk < tkeys.length; tk++) { | ||
var tkey = tkeys[tk]; | ||
for (let tk = 0; tk < tkeys.length; tk++) { | ||
const tkey = tkeys[tk]; | ||
result[tkey] = this[tkey]; | ||
} | ||
|
||
|
@@ -696,9 +696,9 @@ Url.prototype.resolveObject = function resolveObject(relative) { | |
// Hrefs like //foo/bar always cut to the protocol. | ||
if (relative.slashes && !relative.protocol) { | ||
// Take everything except the protocol from relative | ||
var rkeys = Object.keys(relative); | ||
for (var rk = 0; rk < rkeys.length; rk++) { | ||
var rkey = rkeys[rk]; | ||
const rkeys = Object.keys(relative); | ||
for (let rk = 0; rk < rkeys.length; rk++) { | ||
const rkey = rkeys[rk]; | ||
if (rkey !== 'protocol') | ||
result[rkey] = relative[rkey]; | ||
} | ||
|
@@ -723,9 +723,9 @@ Url.prototype.resolveObject = function resolveObject(relative) { | |
// because that's known to be hostless. | ||
// anything else is assumed to be absolute. | ||
if (!slashedProtocol.has(relative.protocol)) { | ||
var keys = Object.keys(relative); | ||
for (var v = 0; v < keys.length; v++) { | ||
var k = keys[v]; | ||
const keys = Object.keys(relative); | ||
for (let v = 0; v < keys.length; v++) { | ||
const k = keys[v]; | ||
result[k] = relative[k]; | ||
} | ||
result.href = result.format(); | ||
|
@@ -754,8 +754,8 @@ Url.prototype.resolveObject = function resolveObject(relative) { | |
result.port = relative.port; | ||
// To support http.request | ||
if (result.pathname || result.search) { | ||
var p = result.pathname || ''; | ||
var s = result.search || ''; | ||
const p = result.pathname || ''; | ||
const s = result.search || ''; | ||
result.path = p + s; | ||
} | ||
result.slashes = result.slashes || relative.slashes; | ||
|
@@ -767,10 +767,10 @@ Url.prototype.resolveObject = function resolveObject(relative) { | |
const isRelAbs = ( | ||
relative.host || (relative.pathname && relative.pathname.charAt(0) === '/') | ||
); | ||
var mustEndAbs = (isRelAbs || isSourceAbs || | ||
let mustEndAbs = (isRelAbs || isSourceAbs || | ||
(result.host && relative.pathname)); | ||
const removeAllDots = mustEndAbs; | ||
var srcPath = (result.pathname && result.pathname.split('/')) || []; | ||
let srcPath = (result.pathname && result.pathname.split('/')) || []; | ||
const relPath = (relative.pathname && relative.pathname.split('/')) || []; | ||
const noLeadingSlashes = result.protocol && | ||
!slashedProtocol.has(result.protocol); | ||
|
@@ -867,15 +867,15 @@ Url.prototype.resolveObject = function resolveObject(relative) { | |
// If a url ENDs in . or .., then it must get a trailing slash. | ||
// however, if it ends in anything else non-slashy, | ||
// then it must NOT get a trailing slash. | ||
var last = srcPath.slice(-1)[0]; | ||
let last = srcPath.slice(-1)[0]; | ||
const hasTrailingSlash = ( | ||
((result.host || relative.host || srcPath.length > 1) && | ||
(last === '.' || last === '..')) || last === ''); | ||
|
||
// Strip single dots, resolve double dots to parent dir | ||
// if the path tries to go above the root, `up` ends up > 0 | ||
var up = 0; | ||
for (var i = srcPath.length - 1; i >= 0; i--) { | ||
let up = 0; | ||
for (let i = srcPath.length - 1; i >= 0; i--) { | ||
last = srcPath[i]; | ||
if (last === '.') { | ||
spliceOne(srcPath, i); | ||
|
@@ -947,8 +947,8 @@ Url.prototype.resolveObject = function resolveObject(relative) { | |
}; | ||
|
||
Url.prototype.parseHost = function parseHost() { | ||
var host = this.host; | ||
var port = portPattern.exec(host); | ||
let host = this.host; | ||
let port = portPattern.exec(host); | ||
if (port) { | ||
port = port[0]; | ||
if (port !== ':') { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move
i = 0
inside the loop on line 166Also, add
let
in a for loop on line 298 and 414?