Carried over from archived repo issue: nodejs/node-v0.x-archive#6100
In: https://nodejs.org/api/url.html#url_url_format_urlobj
It states that: "The protocols http, https, ftp, gopher, file will be postfixed with :// (colon-slash-slash)".
I'm unsure whether urlObjects are meant to be modified so they can be formatted again (although this seems reasonable).
It appears that if the parsed URL was not fully qualified then assigning a protocol doesn't postfix the :// (colon-slash-slash) as expected.
Code below demonstrates the problem:
var url = require("url");
var assert = require("assert");
var fqdnUrl = "http://www.google.com/";
var fqdnObject = url.parse(fqdnUrl);
assert.equal(fqdnObject.protocol, "http:");
assert.equal(url.format(fqdnObject), fqdnUrl);
var partialUrl = "www.google.com/";
var partialObject = url.parse(partialUrl);
assert(!partialObject.protocol);
partialObject.protocol = fqdnObject.protocol; // "http:" (but "http" should also work)
assert.equal(url.format(partialObject), fqdnUrl); // <-- This assertion fails.
Carried over from archived repo issue: nodejs/node-v0.x-archive#6100
In: https://nodejs.org/api/url.html#url_url_format_urlobj
It states that: "The protocols http, https, ftp, gopher, file will be postfixed with :// (colon-slash-slash)".
I'm unsure whether urlObjects are meant to be modified so they can be formatted again (although this seems reasonable).
It appears that if the parsed URL was not fully qualified then assigning a protocol doesn't postfix the :// (colon-slash-slash) as expected.
Code below demonstrates the problem: