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

Extra slash added to url on version 1.19.2 #390

Closed
mansilladev opened this issue Oct 26, 2019 · 3 comments
Closed

Extra slash added to url on version 1.19.2 #390

mansilladev opened this issue Oct 26, 2019 · 3 comments

Comments

@mansilladev
Copy link

4ced30a

The commit above (handle relative paths) on version 1.19.2 causes an extra slash to be added.

var URI = require('urijs');
var url = new URI("atlassian.com");
url.protocol("https");
console.log(url.toString())

Output is:

https:///atlassian.com

@mansilladev
Copy link
Author

mansilladev commented Oct 26, 2019

Perhaps line 686 was meant to be:

if (parts.path.charAt(0) !== '/' && typeof parts.hostname === 'string' && requireAbsolutePath)

@rodneyrehm
Copy link
Member

you're seeing the result of #387

because your url atlassian.com is missing a protocol, it's not parsed as a hostname, but a relative path.

var url = new URI("atlassian.com");
console.log(JSON.stringify(url._parts, null, 2))

outputs

{
  "protocol": null,
  "username": null,
  "password": null,
  "hostname": null,
  "urn": null,
  "port": null,
  "path": "atlassian.com",
  "query": null,
  "fragment": null,
  "preventInvalidHostname": false,
  "duplicateQueryParameters": false,
  "escapeQuerySpace": true
}

Maybe it's time to revisit #260 (and the unfinished attempt at providing a solution: #374) and provide a proper API for what you're trying to do… Are you looking to get your hands dirty with this?

@mansilladev
Copy link
Author

Given that we consistently have just a raw hostname (no proto/scheme/port), perhaps it’s best to start with a blank object, and fill in the parts, eh?

Our library/app (atlassian-connect-express) has been using it the way I described for years, and with recent urijs updates, we started getting reports of the triple slash.

I’ll take a look at #374 and see how dirty I’d like to get my hands. But for the short term, I believe we’ve got a fix. Thanks for your help today, and for your continued support on this library.

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