question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v1.1.0 doesn't de-dupe "/" in relative URLs

See original GitHub issue

It looks like the / deduping regex changed after v0.0.1

// v0.0.1
.replace(/[\/]+/g, '/')

// v1.1.0
.replace(/([^:\s])\/+/g, '$1/')

which means that relative URLs now don’t correctly dedupe leading repeat /.

// v0.0.1
> join("/", "/");
> "/"

// v1.1.0
> join("/", "/");
> "//"

I can work around it in my own code but if this is only intended to support absolute URLs that may be worth calling out.

Alternatively an option (added via the system introduced in #14) to specify if the URL is intended to be relative and use the older regex may be worthwhile. Thoughts? I can send a PR if you’d like.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
eugenet8kcommented, Jul 6, 2016

Also:

> join("", "/some/url");
> "//some/url"

and

> join("/", "someurl");
> "//someurl"
4reactions
ArmorDarkscommented, Feb 26, 2017

That’s definitely works wrong… Any plans to fix this? @jfromaniello?

I think that relative protocol should be supported only when it’s passed explicitly.

This

urljoin('/', '/some')

should return /some

And this

urljoin('//', '/some')

should return //some, since we passed in relative protocol explicitly.

Library shouldn’t make any assumptions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Absolute vs relative URLs - Stack Overflow
This URL is relative to the current path. What this means is that it will resolve to different paths depending on where you...
Read more >
Path — Elixir v1.12.3 - HexDocs
Returns the given path relative to the given from path. In other words, this function tries to strip the from prefix from path...
Read more >
Google: Doesn't Matter if You Use Absolute or Relative URLs ...
John Mueller says, for the most part, it doesn't matter whether you use absolute or relative URLs for internal links.
Read more >
Git Large File Storage (LFS) - GitLab Documentation
Managing large files such as audio, video and graphics files has always been one of the shortcomings of Git. The general recommendation is...
Read more >
[v2] Relative links on MD files doesn't work as expected #2298
Bug Report On v1 it works just fine. When using the relative links it will work only when there is no / at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found