Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

url.format does not postfix :// when parsed url is not fully qualified but a protocol is specified #6100

@andrewwakeling

Description

@andrewwakeling

In:

http://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. 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions