Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is colon required when specifying the protocol #221

Open
humphreyn opened this issue Jan 4, 2022 · 2 comments
Open

Is colon required when specifying the protocol #221

humphreyn opened this issue Jan 4, 2022 · 2 comments

Comments

@humphreyn
Copy link

humphreyn commented Jan 4, 2022

In version 1.5.3 you could build a url without specifying the colin in the protocol as follows:

`
const URL = require("url-parse");

  const myURL = new URL("");

  myURL.set("protocol", "https", true);

  myURL.set("slashes", true, true);

  myURL.set("hostname", "myhostname", true);

  myURL.set("port", 443, true);

  myURL.set("pathname", "my/path", true);

  console.log(myURL.toString());
 // https://myhostname:443/my/path

`
This would print the url as: "https://myhostname:443/my/path"

if you do the same with v1.5.4 it does not print out the slashes, instead you get "https:myhostname:443/my/path".

Is this expected behaviour? Or do you now always have to specify the colon with the protocol?

@lpinca
Copy link
Member

lpinca commented Jan 5, 2022

The problem is that

myURL.set("protocol", "https", true);

sets myURL.slashes to false and myURL.set("slashes", true, true); is a noop in url-parse@1.5.4.

You can add the trailing colon and/or use a falsy third argument in myURL.set("protocol");

myURL.set("protocol", "https:");
myURL.set("protocol", "https:", false);
myURL.set("protocol", "https");
myURL.set("protocol", "https", false);

@lpinca
Copy link
Member

lpinca commented Jan 5, 2022

The proper way is to use the trailing colon so that the library correctly recognizes special protocols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants