Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions lib/url.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,17 +81,18 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
var end = -1;
var rest = '';
var lastPos = 0;
for (var i = 0, inWs = false, split = false; i < url.length; ++i) {
var code = url.charCodeAt(i);
var i = 0;
for (var inWs = false, split = false; i < url.length; ++i) {
const code = url.charCodeAt(i);

// Find first and last non-whitespace characters for trimming
var isWs = code === 32/* */ ||
code === 9/*\t*/ ||
code === 13/*\r*/ ||
code === 10/*\n*/ ||
code === 12/*\f*/ ||
code === 160/*\u00A0*/ ||
code === 65279/*\uFEFF*/;
const isWs = code === 32/* */ ||
code === 9/*\t*/ ||
code === 13/*\r*/ ||
code === 10/*\n*/ ||
code === 12/*\f*/ ||
code === 160/*\u00A0*/ ||
code === 65279/*\uFEFF*/;
if (start === -1) {
if (isWs)
continue;
Expand DownExpand Up@@ -153,7 +154,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {

if (!slashesDenoteHost && !hasHash) {
// Try fast path regexp
var simplePath = simplePathPattern.exec(rest);
const simplePath = simplePathPattern.exec(rest);
if (simplePath) {
this.path = rest;
this.href = rest;
Expand DownExpand Up@@ -215,7 +216,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
var hostEnd = -1;
var atSign = -1;
var nonHost = -1;
for (var i = 0; i < rest.length; ++i) {
for (i = 0; i < rest.length; ++i) {
switch (rest.charCodeAt(i)) {
case 9: // '\t'
case 10: // '\n'
Expand DownExpand Up@@ -255,7 +256,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
if (hostEnd !== -1)
break;
}
var start = 0;
start = 0;
if (atSign !== -1) {
this.auth = decodeURIComponent(rest.slice(0, atSign));
start = atSign + 1;
Expand DownExpand Up@@ -284,9 +285,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
hostname.charCodeAt(hostname.length - 1) === 93/*]*/;

// validate a little.
var result;
if (!ipv6Hostname) {
result = validateHostname(this, rest, hostname);
const result = validateHostname(this, rest, hostname);
if (result !== undefined)
rest = result;
}
Expand DownExpand Up@@ -326,15 +326,15 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// First, make 100% sure that any "autoEscape" chars get
// escaped, even if encodeURIComponent doesn't think they
// need to be.
result = autoEscapeStr(rest);
const result = autoEscapeStr(rest);
if (result !== undefined)
rest = result;
}

var questionIdx = -1;
var hashIdx = -1;
for (var i = 0; i < rest.length; ++i) {
var code = rest.charCodeAt(i);
for (i = 0; i < rest.length; ++i) {
const code = rest.charCodeAt(i);
if (code === 35/*#*/) {
this.hash = rest.slice(i);
hashIdx = i;
Expand DownExpand Up@@ -378,8 +378,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {

// to support http.request
if (this.pathname || this.search) {
var p = this.pathname || '';
var s = this.search || '';
const p = this.pathname || '';
const s = this.search || '';
this.path = p + s;
}

Expand DownExpand Up@@ -720,17 +720,17 @@ Url.prototype.resolveObject = function(relative) {
return result;
}

const isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/');
const isRelAbs = (
var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/');
var isRelAbs = (
relative.host ||
relative.pathname && relative.pathname.charAt(0) === '/'
);
var mustEndAbs = (isRelAbs || isSourceAbs ||
(result.host && relative.pathname));
const removeAllDots = mustEndAbs;
var removeAllDots = mustEndAbs;
var srcPath = result.pathname && result.pathname.split('/') || [];
const relPath = relative.pathname && relative.pathname.split('/') || [];
const psychotic = result.protocol && !slashedProtocol[result.protocol];
var relPath = relative.pathname && relative.pathname.split('/') || [];
var psychotic = result.protocol && !slashedProtocol[result.protocol];

// if the url is a non-slashed url, then relative
// links like ../.. should be able
Expand Down