Browse Source

url: change scoping of variables with let

Also changes some `var`s to `const` as they never change.

PR-URL: https://github.com/nodejs/node/pull/4867
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
process-exit-stdio-flushing
Kári Tristan Helgason 9 years ago
committed by Rich Trott
parent
commit
fcae05e4b5
  1. 30
      lib/url.js

30
lib/url.js

@ -169,8 +169,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// find the first instance of any hostEndingChars // find the first instance of any hostEndingChars
var hostEnd = -1; var hostEnd = -1;
for (var i = 0; i < hostEndingChars.length; i++) { for (let i = 0; i < hostEndingChars.length; i++) {
var hec = rest.indexOf(hostEndingChars[i]); const hec = rest.indexOf(hostEndingChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec; hostEnd = hec;
} }
@ -197,8 +197,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// the host is the remaining to the left of the first non-host char // the host is the remaining to the left of the first non-host char
hostEnd = -1; hostEnd = -1;
for (var i = 0; i < nonHostChars.length; i++) { for (let i = 0; i < nonHostChars.length; i++) {
var hec = rest.indexOf(nonHostChars[i]); const hec = rest.indexOf(nonHostChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec; hostEnd = hec;
} }
@ -224,12 +224,12 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// validate a little. // validate a little.
if (!ipv6Hostname) { if (!ipv6Hostname) {
var hostparts = this.hostname.split(/\./); var hostparts = this.hostname.split(/\./);
for (var i = 0, l = hostparts.length; i < l; i++) { for (let i = 0, l = hostparts.length; i < l; i++) {
var part = hostparts[i]; var part = hostparts[i];
if (!part) continue; if (!part) continue;
if (!part.match(hostnamePartPattern)) { if (!part.match(hostnamePartPattern)) {
var newpart = ''; var newpart = '';
for (var j = 0, k = part.length; j < k; j++) { for (let j = 0, k = part.length; j < k; j++) {
if (part.charCodeAt(j) > 127) { if (part.charCodeAt(j) > 127) {
// we replace non-ASCII char with a temporary placeholder // we replace non-ASCII char with a temporary placeholder
// we need this to make sure size of hostname is not // we need this to make sure size of hostname is not
@ -294,7 +294,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// First, make 100% sure that any "autoEscape" chars get // First, make 100% sure that any "autoEscape" chars get
// escaped, even if encodeURIComponent doesn't think they // escaped, even if encodeURIComponent doesn't think they
// need to be. // need to be.
for (var i = 0, l = autoEscape.length; i < l; i++) { for (let i = 0, l = autoEscape.length; i < l; i++) {
var ae = autoEscape[i]; var ae = autoEscape[i];
if (rest.indexOf(ae) === -1) if (rest.indexOf(ae) === -1)
continue; continue;
@ -335,8 +335,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
//to support http.request //to support http.request
if (this.pathname || this.search) { if (this.pathname || this.search) {
var p = this.pathname || ''; const p = this.pathname || '';
var s = this.search || ''; const s = this.search || '';
this.path = p + s; this.path = p + s;
} }
@ -498,7 +498,7 @@ Url.prototype.resolveObject = function(relative) {
if (!relative.host && if (!relative.host &&
!/^file:?$/.test(relative.protocol) && !/^file:?$/.test(relative.protocol) &&
!hostlessProtocol[relative.protocol]) { !hostlessProtocol[relative.protocol]) {
var relPath = (relative.pathname || '').split('/'); const relPath = (relative.pathname || '').split('/');
while (relPath.length && !(relative.host = relPath.shift())); while (relPath.length && !(relative.host = relPath.shift()));
if (!relative.host) relative.host = ''; if (!relative.host) relative.host = '';
if (!relative.hostname) relative.hostname = ''; if (!relative.hostname) relative.hostname = '';
@ -533,8 +533,8 @@ Url.prototype.resolveObject = function(relative) {
var mustEndAbs = (isRelAbs || isSourceAbs || var mustEndAbs = (isRelAbs || isSourceAbs ||
(result.host && relative.pathname)); (result.host && relative.pathname));
const removeAllDots = mustEndAbs; const removeAllDots = mustEndAbs;
var srcPath = result.pathname && result.pathname.split('/') || []; let srcPath = result.pathname && result.pathname.split('/') || [];
var relPath = relative.pathname && relative.pathname.split('/') || []; const relPath = relative.pathname && relative.pathname.split('/') || [];
const psychotic = result.protocol && !slashedProtocol[result.protocol]; const psychotic = result.protocol && !slashedProtocol[result.protocol];
// if the url is a non-slashed url, then relative // if the url is a non-slashed url, then relative
@ -589,7 +589,7 @@ Url.prototype.resolveObject = function(relative) {
//occasionally the auth can get stuck only in host //occasionally the auth can get stuck only in host
//this especially happens in cases like //this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2') //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
var authInHost = result.host && result.host.indexOf('@') > 0 ? const authInHost = result.host && result.host.indexOf('@') > 0 ?
result.host.split('@') : false; result.host.split('@') : false;
if (authInHost) { if (authInHost) {
result.auth = authInHost.shift(); result.auth = authInHost.shift();
@ -632,7 +632,7 @@ Url.prototype.resolveObject = function(relative) {
// strip single dots, resolve double dots to parent dir // strip single dots, resolve double dots to parent dir
// if the path tries to go above the root, `up` ends up > 0 // if the path tries to go above the root, `up` ends up > 0
var up = 0; var up = 0;
for (var i = srcPath.length; i >= 0; i--) { for (let i = srcPath.length; i >= 0; i--) {
last = srcPath[i]; last = srcPath[i];
if (last === '.') { if (last === '.') {
spliceOne(srcPath, i); spliceOne(srcPath, i);
@ -671,7 +671,7 @@ Url.prototype.resolveObject = function(relative) {
//occasionally the auth can get stuck only in host //occasionally the auth can get stuck only in host
//this especially happens in cases like //this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2') //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
var authInHost = result.host && result.host.indexOf('@') > 0 ? const authInHost = result.host && result.host.indexOf('@') > 0 ?
result.host.split('@') : false; result.host.split('@') : false;
if (authInHost) { if (authInHost) {
result.auth = authInHost.shift(); result.auth = authInHost.shift();

Loading…
Cancel
Save