Skip to content

url.format does not postfix slashes to protocol but doc pretend it should by default #3361

Closed
@sdumetz

Description

@sdumetz

Quoting the doc :

protocol is treated the same with or without the trailing : (colon).
The protocols http, https, ftp, gopher, file will be postfixed with :// (colon-slash-slash).
All other protocols mailto, xmpp, aim, sftp, foo, etc will be postfixed with : (colon).
slashes set to true if the protocol requires :// (colon-slash-slash)
Only needs to be set for protocols not previously listed as requiring slashes, such as mongodb://localhost:8000/.

But a quick test (using nodejs V4.1) show the problem:

url = require("url");
uri = url.parse("/home/user");
uri.protocol = "file";
console.log(url.format(uri));

Output : file:/home/user. While the expected output is : file:///home/user

Setting uri.slashes = true make it format the correct URL.

I think it's not worth it to modify the module itself as it's stable. However the doc should be updated to reflect this behaviour.

Should I submit a PR reflecting this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    semver-majorPRs that contain breaking changes and should be released in the next major version.urlIssues and PRs related to the legacy built-in url module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions