trailing whitespace fixes
This commit is contained in:
parent
93913dbdb8
commit
57fbb627ca
@ -112,7 +112,7 @@ assert.equal = function equal(actual, expected, message) {
|
|||||||
// with != assert.notEqual(actual, expected, message_opt);
|
// with != assert.notEqual(actual, expected, message_opt);
|
||||||
|
|
||||||
assert.notEqual = function notEqual(actual, expected, message) {
|
assert.notEqual = function notEqual(actual, expected, message) {
|
||||||
if (actual == expected) {
|
if (actual == expected) {
|
||||||
fail(actual, expected, message, "!=", assert.notEqual);
|
fail(actual, expected, message, "!=", assert.notEqual);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -98,7 +98,7 @@ function stringToFlags(flag) {
|
|||||||
case "r+": return process.O_RDWR;
|
case "r+": return process.O_RDWR;
|
||||||
case "w": return process.O_CREAT | process.O_TRUNC | process.O_WRONLY;
|
case "w": return process.O_CREAT | process.O_TRUNC | process.O_WRONLY;
|
||||||
case "w+": return process.O_CREAT | process.O_TRUNC | process.O_RDWR;
|
case "w+": return process.O_CREAT | process.O_TRUNC | process.O_RDWR;
|
||||||
case "a": return process.O_APPEND | process.O_CREAT | process.O_WRONLY;
|
case "a": return process.O_APPEND | process.O_CREAT | process.O_WRONLY;
|
||||||
case "a+": return process.O_APPEND | process.O_CREAT | process.O_RDWR;
|
case "a+": return process.O_APPEND | process.O_CREAT | process.O_RDWR;
|
||||||
default: throw new Error("Unknown file open flag: " + flag);
|
default: throw new Error("Unknown file open flag: " + flag);
|
||||||
}
|
}
|
||||||
@ -707,7 +707,7 @@ var writeStreamCloseWarning;
|
|||||||
FileWriteStream.prototype.close = function (cb) {
|
FileWriteStream.prototype.close = function (cb) {
|
||||||
if (!writeStreamCloseWarning) {
|
if (!writeStreamCloseWarning) {
|
||||||
writeStreamCloseWarning = "FileWriteStream.prototype.close renamed to end()";
|
writeStreamCloseWarning = "FileWriteStream.prototype.close renamed to end()";
|
||||||
sys.error(writeStreamCloseWarning);
|
sys.error(writeStreamCloseWarning);
|
||||||
}
|
}
|
||||||
return this.end(cb);
|
return this.end(cb);
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ OutgoingMessage.prototype.sendHeaderLines = function (first_line, headers) {
|
|||||||
|
|
||||||
|
|
||||||
OutgoingMessage.prototype.sendBody = function () {
|
OutgoingMessage.prototype.sendBody = function () {
|
||||||
throw new Error("sendBody() has been renamed to write(). " +
|
throw new Error("sendBody() has been renamed to write(). " +
|
||||||
"The 'body' event has been renamed to 'data' and " +
|
"The 'body' event has been renamed to 'data' and " +
|
||||||
"the 'complete' event has been renamed to 'end'.");
|
"the 'complete' event has been renamed to 'end'.");
|
||||||
};
|
};
|
||||||
@ -338,7 +338,7 @@ function createIncomingMessageStream (connection, incoming_listener) {
|
|||||||
field = null;
|
field = null;
|
||||||
value = null;
|
value = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Only servers will get URL events.
|
// Only servers will get URL events.
|
||||||
connection.addListener("url", function (data) {
|
connection.addListener("url", function (data) {
|
||||||
incoming.url += data;
|
incoming.url += data;
|
||||||
@ -580,7 +580,7 @@ http.Client.prototype.request = function (method, url, headers) {
|
|||||||
|
|
||||||
|
|
||||||
exports.cat = function (url, encoding_, headers_) {
|
exports.cat = function (url, encoding_, headers_) {
|
||||||
var encoding = 'utf8',
|
var encoding = 'utf8',
|
||||||
headers = {},
|
headers = {},
|
||||||
callback = null;
|
callback = null;
|
||||||
|
|
||||||
@ -604,7 +604,7 @@ exports.cat = function (url, encoding_, headers_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var url = require("url").parse(url);
|
var url = require("url").parse(url);
|
||||||
|
|
||||||
var hasHost = false;
|
var hasHost = false;
|
||||||
for (var i in headers) {
|
for (var i in headers) {
|
||||||
if (i.toLowerCase() === "host") {
|
if (i.toLowerCase() === "host") {
|
||||||
@ -615,7 +615,7 @@ exports.cat = function (url, encoding_, headers_) {
|
|||||||
if (!hasHost) headers["Host"] = url.hostname;
|
if (!hasHost) headers["Host"] = url.hostname;
|
||||||
|
|
||||||
var content = "";
|
var content = "";
|
||||||
|
|
||||||
var client = exports.createClient(url.port || 80, url.hostname);
|
var client = exports.createClient(url.port || 80, url.hostname);
|
||||||
var req = client.request((url.pathname || "/")+(url.search || "")+(url.hash || ""), headers);
|
var req = client.request((url.pathname || "/")+(url.search || "")+(url.hash || ""), headers);
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ function initStream (self) {
|
|||||||
self.readable = false;
|
self.readable = false;
|
||||||
|
|
||||||
// Queue of buffers and string that need to be written to socket.
|
// Queue of buffers and string that need to be written to socket.
|
||||||
self._writeQueue = [];
|
self._writeQueue = [];
|
||||||
self._writeQueueEncoding = [];
|
self._writeQueueEncoding = [];
|
||||||
|
|
||||||
self._writeWatcher = ioWatchers.alloc();
|
self._writeWatcher = ioWatchers.alloc();
|
||||||
@ -608,7 +608,7 @@ Stream.prototype.connect = function () {
|
|||||||
initStream(self);
|
initStream(self);
|
||||||
if (self.fd) throw new Error('Stream already opened');
|
if (self.fd) throw new Error('Stream already opened');
|
||||||
if (!self._readWatcher) throw new Error('No readWatcher');
|
if (!self._readWatcher) throw new Error('No readWatcher');
|
||||||
|
|
||||||
timeout.active(socket);
|
timeout.active(socket);
|
||||||
|
|
||||||
var port = parseInt(arguments[0]);
|
var port = parseInt(arguments[0]);
|
||||||
|
@ -30,7 +30,7 @@ QueryString.stringify = function (obj, sep, eq, name) {
|
|||||||
if (isA(obj, null) || isA(obj, undefined) || typeof(obj) === 'function') {
|
if (isA(obj, null) || isA(obj, undefined) || typeof(obj) === 'function') {
|
||||||
return name ? encodeURIComponent(name) + eq : '';
|
return name ? encodeURIComponent(name) + eq : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBool(obj)) obj = +obj;
|
if (isBool(obj)) obj = +obj;
|
||||||
if (isNumber(obj) || isString(obj)) {
|
if (isNumber(obj) || isString(obj)) {
|
||||||
return encodeURIComponent(name) + eq + encodeURIComponent(obj);
|
return encodeURIComponent(name) + eq + encodeURIComponent(obj);
|
||||||
@ -44,14 +44,14 @@ QueryString.stringify = function (obj, sep, eq, name) {
|
|||||||
return s.join(sep);
|
return s.join(sep);
|
||||||
}
|
}
|
||||||
// now we know it's an object.
|
// now we know it's an object.
|
||||||
|
|
||||||
// Check for cyclical references in nested objects
|
// Check for cyclical references in nested objects
|
||||||
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] === obj) {
|
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] === obj) {
|
||||||
throw new Error("querystring.stringify. Cyclical reference");
|
throw new Error("querystring.stringify. Cyclical reference");
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.push(obj);
|
stack.push(obj);
|
||||||
|
|
||||||
var s = [];
|
var s = [];
|
||||||
var begin = name ? name + '[' : '';
|
var begin = name ? name + '[' : '';
|
||||||
var end = name ? ']' : '';
|
var end = name ? ']' : '';
|
||||||
@ -59,9 +59,9 @@ QueryString.stringify = function (obj, sep, eq, name) {
|
|||||||
var n = begin + i + end;
|
var n = begin + i + end;
|
||||||
s.push(QueryString.stringify(obj[i], sep, eq, n));
|
s.push(QueryString.stringify(obj[i], sep, eq, n));
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.pop();
|
stack.pop();
|
||||||
|
|
||||||
s = s.join(sep);
|
s = s.join(sep);
|
||||||
if (!s && name) return name + "=";
|
if (!s && name) return name + "=";
|
||||||
return s;
|
return s;
|
||||||
@ -112,10 +112,10 @@ var pieceParser = function (eq) {
|
|||||||
}
|
}
|
||||||
// ["foo[][bar][][baz]", "foo[][bar][]", "baz"]
|
// ["foo[][bar][][baz]", "foo[][bar][]", "baz"]
|
||||||
var tail = sliced[2], head = sliced[1];
|
var tail = sliced[2], head = sliced[1];
|
||||||
|
|
||||||
// array: key[]=val
|
// array: key[]=val
|
||||||
if (!tail) return parsePiece(head, [val]);
|
if (!tail) return parsePiece(head, [val]);
|
||||||
|
|
||||||
// obj: key[subkey]=val
|
// obj: key[subkey]=val
|
||||||
var ret = {};
|
var ret = {};
|
||||||
ret[tail] = val;
|
ret[tail] = val;
|
||||||
|
28
lib/repl.js
28
lib/repl.js
@ -32,13 +32,13 @@ exports.start = function (prompt) {
|
|||||||
*/
|
*/
|
||||||
function readline (cmd) {
|
function readline (cmd) {
|
||||||
cmd = trimWhitespace(cmd);
|
cmd = trimWhitespace(cmd);
|
||||||
|
|
||||||
// Check to see if a REPL keyword was used. If it returns true,
|
// Check to see if a REPL keyword was used. If it returns true,
|
||||||
// display next prompt and return.
|
// display next prompt and return.
|
||||||
if (parseREPLKeyword(cmd) === true) {
|
if (parseREPLKeyword(cmd) === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The catchall for errors
|
// The catchall for errors
|
||||||
try {
|
try {
|
||||||
buffered_cmd += "\n" + cmd;
|
buffered_cmd += "\n" + cmd;
|
||||||
@ -46,7 +46,7 @@ function readline (cmd) {
|
|||||||
// continue onto the next line.
|
// continue onto the next line.
|
||||||
try {
|
try {
|
||||||
buffered_cmd = convertToScope(buffered_cmd);
|
buffered_cmd = convertToScope(buffered_cmd);
|
||||||
|
|
||||||
// Scope the readline with exports.scope to provide "local" vars
|
// Scope the readline with exports.scope to provide "local" vars
|
||||||
with (exports.scope) {
|
with (exports.scope) {
|
||||||
var ret = eval(buffered_cmd);
|
var ret = eval(buffered_cmd);
|
||||||
@ -55,7 +55,7 @@ function readline (cmd) {
|
|||||||
exports.writer(ret);
|
exports.writer(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffered_cmd = '';
|
buffered_cmd = '';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!(e instanceof SyntaxError)) throw e;
|
if (!(e instanceof SyntaxError)) throw e;
|
||||||
@ -69,13 +69,13 @@ function readline (cmd) {
|
|||||||
}
|
}
|
||||||
buffered_cmd = '';
|
buffered_cmd = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
displayPrompt();
|
displayPrompt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to display the prompt.
|
* Used to display the prompt.
|
||||||
*/
|
*/
|
||||||
function displayPrompt () {
|
function displayPrompt () {
|
||||||
sys.print(buffered_cmd.length ? '... ' : exports.prompt);
|
sys.print(buffered_cmd.length ? '... ' : exports.prompt);
|
||||||
@ -83,9 +83,9 @@ function displayPrompt () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to parse and execute the Node REPL commands.
|
* Used to parse and execute the Node REPL commands.
|
||||||
*
|
*
|
||||||
* @param {cmd} cmd The command entered to check
|
* @param {cmd} cmd The command entered to check
|
||||||
* @returns {Boolean} If true it means don't continue parsing the command
|
* @returns {Boolean} If true it means don't continue parsing the command
|
||||||
*/
|
*/
|
||||||
function parseREPLKeyword (cmd) {
|
function parseREPLKeyword (cmd) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
@ -115,9 +115,9 @@ function parseREPLKeyword (cmd) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Trims Whitespace from a line.
|
* Trims Whitespace from a line.
|
||||||
*
|
*
|
||||||
* @param {String} cmd The string to trim the whitespace from
|
* @param {String} cmd The string to trim the whitespace from
|
||||||
* @returns {String} The trimmed string
|
* @returns {String} The trimmed string
|
||||||
*/
|
*/
|
||||||
function trimWhitespace (cmd) {
|
function trimWhitespace (cmd) {
|
||||||
var matches = trimmer.exec(cmd);
|
var matches = trimmer.exec(cmd);
|
||||||
@ -130,24 +130,24 @@ function trimWhitespace (cmd) {
|
|||||||
* Converts commands that use var and function <name>() to use the
|
* Converts commands that use var and function <name>() to use the
|
||||||
* local exports.scope when evaled. This provides a local scope
|
* local exports.scope when evaled. This provides a local scope
|
||||||
* on the REPL.
|
* on the REPL.
|
||||||
*
|
*
|
||||||
* @param {String} cmd The cmd to convert
|
* @param {String} cmd The cmd to convert
|
||||||
* @returns {String} The converted command
|
* @returns {String} The converted command
|
||||||
*/
|
*/
|
||||||
function convertToScope (cmd) {
|
function convertToScope (cmd) {
|
||||||
var matches;
|
var matches;
|
||||||
|
|
||||||
// Replaces: var foo = "bar"; with: exports.scope.foo = bar;
|
// Replaces: var foo = "bar"; with: exports.scope.foo = bar;
|
||||||
matches = scopedVar.exec(cmd);
|
matches = scopedVar.exec(cmd);
|
||||||
if (matches && matches.length == 3) {
|
if (matches && matches.length == 3) {
|
||||||
return "exports.scope." + matches[1] + matches[2];
|
return "exports.scope." + matches[1] + matches[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replaces: function foo() {}; with: foo = function foo() {};
|
// Replaces: function foo() {}; with: foo = function foo() {};
|
||||||
matches = scopeFunc.exec(buffered_cmd);
|
matches = scopeFunc.exec(buffered_cmd);
|
||||||
if (matches && matches.length == 2) {
|
if (matches && matches.length == 2) {
|
||||||
return matches[1] + " = " + buffered_cmd;
|
return matches[1] + " = " + buffered_cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ exports.inspect = function (obj, showHidden, depth) {
|
|||||||
} else {
|
} else {
|
||||||
base = "";
|
base = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make dates with properties first say the date
|
// Make dates with properties first say the date
|
||||||
if (value instanceof Date) {
|
if (value instanceof Date) {
|
||||||
base = ' ' + value.toUTCString();
|
base = ' ' + value.toUTCString();
|
||||||
@ -160,7 +160,7 @@ exports.inspect = function (obj, showHidden, depth) {
|
|||||||
|
|
||||||
return name + ": " + str;
|
return name + ": " + str;
|
||||||
});
|
});
|
||||||
|
|
||||||
var numLinesEst = 0;
|
var numLinesEst = 0;
|
||||||
var length = output.reduce(function(prev, cur) {
|
var length = output.reduce(function(prev, cur) {
|
||||||
numLinesEst++;
|
numLinesEst++;
|
||||||
|
62
lib/url.js
62
lib/url.js
@ -20,17 +20,17 @@ var protocolPattern = /^([a-z0-9]+:)/,
|
|||||||
|
|
||||||
function urlParse (url, parseQueryString) {
|
function urlParse (url, parseQueryString) {
|
||||||
if (url && typeof(url) === "object" && url.href) return url;
|
if (url && typeof(url) === "object" && url.href) return url;
|
||||||
|
|
||||||
var out = { href : url },
|
var out = { href : url },
|
||||||
rest = url;
|
rest = url;
|
||||||
|
|
||||||
var proto = protocolPattern.exec(rest);
|
var proto = protocolPattern.exec(rest);
|
||||||
if (proto) {
|
if (proto) {
|
||||||
proto = proto[0];
|
proto = proto[0];
|
||||||
out.protocol = proto;
|
out.protocol = proto;
|
||||||
rest = rest.substr(proto.length);
|
rest = rest.substr(proto.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// figure out if it's got a host
|
// figure out if it's got a host
|
||||||
var slashes = rest.substr(0, 2) === "//";
|
var slashes = rest.substr(0, 2) === "//";
|
||||||
if (slashes && !(proto && hostlessProtocol[proto])) {
|
if (slashes && !(proto && hostlessProtocol[proto])) {
|
||||||
@ -48,19 +48,19 @@ function urlParse (url, parseQueryString) {
|
|||||||
}
|
}
|
||||||
if (firstNonHost !== -1) {
|
if (firstNonHost !== -1) {
|
||||||
out.host = rest.substr(0, firstNonHost);
|
out.host = rest.substr(0, firstNonHost);
|
||||||
rest = rest.substr(firstNonHost);
|
rest = rest.substr(firstNonHost);
|
||||||
} else {
|
} else {
|
||||||
out.host = rest;
|
out.host = rest;
|
||||||
rest = "";
|
rest = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// pull out the auth and port.
|
// pull out the auth and port.
|
||||||
var p = parseHost(out.host);
|
var p = parseHost(out.host);
|
||||||
for (var i in p) out[i] = p[i];
|
for (var i in p) out[i] = p[i];
|
||||||
// we've indicated that there is a hostname, so even if it's empty, it has to be present.
|
// we've indicated that there is a hostname, so even if it's empty, it has to be present.
|
||||||
out.hostname = out.hostname || "";
|
out.hostname = out.hostname || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// now rest is set to the post-host stuff.
|
// now rest is set to the post-host stuff.
|
||||||
// chop off from the tail first.
|
// chop off from the tail first.
|
||||||
var hash = rest.indexOf("#");
|
var hash = rest.indexOf("#");
|
||||||
@ -79,7 +79,7 @@ function urlParse (url, parseQueryString) {
|
|||||||
rest = rest.slice(0, qm);
|
rest = rest.slice(0, qm);
|
||||||
}
|
}
|
||||||
if (rest) out.pathname = rest;
|
if (rest) out.pathname = rest;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,37 +88,37 @@ function urlFormat (obj) {
|
|||||||
// ensure it's an object, and not a string url. If it's an obj, this is a no-op.
|
// ensure it's an object, and not a string url. If it's an obj, this is a no-op.
|
||||||
// this way, you can call url_format() on strings to clean up potentially wonky urls.
|
// this way, you can call url_format() on strings to clean up potentially wonky urls.
|
||||||
if (typeof(obj) === "string") obj = urlParse(obj);
|
if (typeof(obj) === "string") obj = urlParse(obj);
|
||||||
|
|
||||||
var protocol = obj.protocol || "",
|
var protocol = obj.protocol || "",
|
||||||
host = (obj.host !== undefined) ? obj.host
|
host = (obj.host !== undefined) ? obj.host
|
||||||
: obj.hostname !== undefined ? (
|
: obj.hostname !== undefined ? (
|
||||||
(obj.auth ? obj.auth + "@" : "")
|
(obj.auth ? obj.auth + "@" : "")
|
||||||
+ obj.hostname
|
+ obj.hostname
|
||||||
+ (obj.port ? ":" + obj.port : "")
|
+ (obj.port ? ":" + obj.port : "")
|
||||||
)
|
)
|
||||||
: false,
|
: false,
|
||||||
pathname = obj.pathname || "",
|
pathname = obj.pathname || "",
|
||||||
search = obj.search || (
|
search = obj.search || (
|
||||||
obj.query && ( "?" + (
|
obj.query && ( "?" + (
|
||||||
typeof(obj.query) === "object"
|
typeof(obj.query) === "object"
|
||||||
? querystring.stringify(obj.query)
|
? querystring.stringify(obj.query)
|
||||||
: String(obj.query)
|
: String(obj.query)
|
||||||
))
|
))
|
||||||
) || "",
|
) || "",
|
||||||
hash = obj.hash || "";
|
hash = obj.hash || "";
|
||||||
|
|
||||||
if (protocol && protocol.substr(-1) !== ":") protocol += ":";
|
if (protocol && protocol.substr(-1) !== ":") protocol += ":";
|
||||||
|
|
||||||
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
|
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
|
||||||
// unless they had them to begin with.
|
// unless they had them to begin with.
|
||||||
if (obj.slashes || (!protocol || slashedProtocol[protocol]) && host !== false) {
|
if (obj.slashes || (!protocol || slashedProtocol[protocol]) && host !== false) {
|
||||||
host = "//" + (host || "");
|
host = "//" + (host || "");
|
||||||
if (pathname && pathname.charAt(0) !== "/") pathname = "/" + pathname;
|
if (pathname && pathname.charAt(0) !== "/") pathname = "/" + pathname;
|
||||||
} else if (!host) host = "";
|
} else if (!host) host = "";
|
||||||
|
|
||||||
if (hash && hash.charAt(0) !== "#") hash = "#" + hash;
|
if (hash && hash.charAt(0) !== "#") hash = "#" + hash;
|
||||||
if (search && search.charAt(0) !== "?") search = "?" + search;
|
if (search && search.charAt(0) !== "?") search = "?" + search;
|
||||||
|
|
||||||
return protocol + host + pathname + search + hash;
|
return protocol + host + pathname + search + hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -128,30 +128,30 @@ function urlResolve (source, relative) {
|
|||||||
|
|
||||||
function urlResolveObject (source, relative) {
|
function urlResolveObject (source, relative) {
|
||||||
if (!source) return relative;
|
if (!source) return relative;
|
||||||
|
|
||||||
source = urlParse(urlFormat(source));
|
source = urlParse(urlFormat(source));
|
||||||
relative = urlParse(urlFormat(relative));
|
relative = urlParse(urlFormat(relative));
|
||||||
|
|
||||||
// hash is always overridden, no matter what.
|
// hash is always overridden, no matter what.
|
||||||
source.hash = relative.hash;
|
source.hash = relative.hash;
|
||||||
|
|
||||||
if (relative.href === "") return source;
|
if (relative.href === "") return source;
|
||||||
|
|
||||||
// hrefs like //foo/bar always cut to the protocol.
|
// hrefs like //foo/bar always cut to the protocol.
|
||||||
if (relative.slashes && !relative.protocol) {
|
if (relative.slashes && !relative.protocol) {
|
||||||
relative.protocol = source.protocol;
|
relative.protocol = source.protocol;
|
||||||
return relative;
|
return relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relative.protocol && relative.protocol !== source.protocol) {
|
if (relative.protocol && relative.protocol !== source.protocol) {
|
||||||
// if it's a known url protocol, then changing the protocol does weird things
|
// if it's a known url protocol, then changing the protocol does weird things
|
||||||
// first, if it's not file:, then we MUST have a host, and if there was a path
|
// first, if it's not file:, then we MUST have a host, and if there was a path
|
||||||
// to begin with, then we MUST have a path.
|
// to begin with, then we MUST have a path.
|
||||||
// if it is file:, then the host is dropped, because that's known to be hostless.
|
// if it is file:, then the host is dropped, because that's known to be hostless.
|
||||||
// anything else is assumed to be absolute.
|
// anything else is assumed to be absolute.
|
||||||
|
|
||||||
if (!slashedProtocol[relative.protocol]) return relative;
|
if (!slashedProtocol[relative.protocol]) return relative;
|
||||||
|
|
||||||
source.protocol = relative.protocol;
|
source.protocol = relative.protocol;
|
||||||
if (!relative.host && !hostlessProtocol[relative.protocol]) {
|
if (!relative.host && !hostlessProtocol[relative.protocol]) {
|
||||||
var relPath = (relative.pathname || "").split("/");
|
var relPath = (relative.pathname || "").split("/");
|
||||||
@ -181,13 +181,13 @@ function urlResolveObject (source, relative) {
|
|||||||
srcPath = source.pathname && source.pathname.split("/") || [],
|
srcPath = source.pathname && source.pathname.split("/") || [],
|
||||||
relPath = relative.pathname && relative.pathname.split("/") || [],
|
relPath = relative.pathname && relative.pathname.split("/") || [],
|
||||||
psychotic = source.protocol && !slashedProtocol[source.protocol] && source.host !== undefined;
|
psychotic = source.protocol && !slashedProtocol[source.protocol] && source.host !== undefined;
|
||||||
|
|
||||||
// if the url is a non-slashed url, then relative links like ../.. should be able
|
// if the url is a non-slashed url, then relative links like ../.. should be able
|
||||||
// to crawl up to the hostname, as well. This is strange.
|
// to crawl up to the hostname, as well. This is strange.
|
||||||
// source.protocol has already been set by now.
|
// source.protocol has already been set by now.
|
||||||
// Later on, put the first path part into the host field.
|
// Later on, put the first path part into the host field.
|
||||||
if ( psychotic ) {
|
if ( psychotic ) {
|
||||||
|
|
||||||
delete source.hostname;
|
delete source.hostname;
|
||||||
delete source.auth;
|
delete source.auth;
|
||||||
delete source.port;
|
delete source.port;
|
||||||
@ -196,7 +196,7 @@ function urlResolveObject (source, relative) {
|
|||||||
else srcPath.unshift(source.host);
|
else srcPath.unshift(source.host);
|
||||||
}
|
}
|
||||||
delete source.host;
|
delete source.host;
|
||||||
|
|
||||||
if (relative.protocol) {
|
if (relative.protocol) {
|
||||||
delete relative.hostname;
|
delete relative.hostname;
|
||||||
delete relative.auth;
|
delete relative.auth;
|
||||||
@ -209,7 +209,7 @@ function urlResolveObject (source, relative) {
|
|||||||
}
|
}
|
||||||
mustEndAbs = mustEndAbs && (relPath[0] === "" || srcPath[0] === "");
|
mustEndAbs = mustEndAbs && (relPath[0] === "" || srcPath[0] === "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRelAbs) {
|
if (isRelAbs) {
|
||||||
// it's absolute.
|
// it's absolute.
|
||||||
source.host = (relative.host || relative.host === "") ? relative.host : source.host;
|
source.host = (relative.host || relative.host === "") ? relative.host : source.host;
|
||||||
@ -242,7 +242,7 @@ function urlResolveObject (source, relative) {
|
|||||||
delete source.pathname;
|
delete source.pathname;
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve dots.
|
// resolve dots.
|
||||||
// if a url ENDs in . or .., then it must get a trailing slash.
|
// 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.
|
// however, if it ends in anything else non-slashy, then it must NOT get a trailing slash.
|
||||||
@ -251,7 +251,7 @@ function urlResolveObject (source, relative) {
|
|||||||
(source.host || relative.host) && (last === "." || last === "..")
|
(source.host || relative.host) && (last === "." || last === "..")
|
||||||
|| last === ""
|
|| last === ""
|
||||||
);
|
);
|
||||||
|
|
||||||
// Figure out if this has to end up as an absolute url, or should continue to be relative.
|
// Figure out if this has to end up as an absolute url, or should continue to be relative.
|
||||||
srcPath = path.normalizeArray(srcPath, true);
|
srcPath = path.normalizeArray(srcPath, true);
|
||||||
if (srcPath.length === 1 && srcPath[0] === ".") srcPath = [];
|
if (srcPath.length === 1 && srcPath[0] === ".") srcPath = [];
|
||||||
@ -262,23 +262,23 @@ function urlResolveObject (source, relative) {
|
|||||||
if (dir === "..") dirs.pop();
|
if (dir === "..") dirs.pop();
|
||||||
else if (dir !== ".") dirs.push(dir);
|
else if (dir !== ".") dirs.push(dir);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (mustEndAbs && dirs[0] !== "") {
|
if (mustEndAbs && dirs[0] !== "") {
|
||||||
dirs.unshift("");
|
dirs.unshift("");
|
||||||
}
|
}
|
||||||
srcPath = dirs;
|
srcPath = dirs;
|
||||||
}
|
}
|
||||||
if (hasTrailingSlash && (srcPath.length < 2 || srcPath.slice(-1)[0] !== "")) srcPath.push("");
|
if (hasTrailingSlash && (srcPath.length < 2 || srcPath.slice(-1)[0] !== "")) srcPath.push("");
|
||||||
|
|
||||||
// put the host back
|
// put the host back
|
||||||
if ( psychotic ) source.host = srcPath[0] === "" ? "" : srcPath.shift();
|
if ( psychotic ) source.host = srcPath[0] === "" ? "" : srcPath.shift();
|
||||||
|
|
||||||
mustEndAbs = mustEndAbs || (source.host && srcPath.length);
|
mustEndAbs = mustEndAbs || (source.host && srcPath.length);
|
||||||
|
|
||||||
if (mustEndAbs && srcPath[0] !== "") srcPath.unshift("")
|
if (mustEndAbs && srcPath[0] !== "") srcPath.unshift("")
|
||||||
|
|
||||||
source.pathname = srcPath.join("/");
|
source.pathname = srcPath.join("/");
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user