Kotsu icon indicating copy to clipboard operation
Kotsu copied to clipboard

`urljoin` encoding issue

Open ArmorDarks opened this issue 7 years ago • 1 comments

Seems there is an issue with urljoin.

Due to the way how URI.js works, it always encodes URLS.

It becomes true issue for cyrillic urls, which ends up after joining as mess a mess like %%303%%%

Current blunt solution would be to force-decode urls:

module.exports = (...urls) => {
  const [firstUrl, ...restUrls] = urls
  const uri = URI(firstUrl)
  const hasProtocol = uri.protocol()

  if (hasProtocol) {
    // @todo Something has to be done with the fact that URI.js force-encodes urls
-    return URI.joinPaths(...restUrls).absoluteTo(uri).valueOf()
+    return URI.decode(URI.joinPaths(...restUrls).absoluteTo(uri).valueOf())
  }

  let path = URI.joinPaths(...urls).valueOf()

  // @todo Workaround for https://github.com/medialize/URI.js/issues/341
  if (!path.startsWith('/') && firstUrl === '/') {
    path = `/${path}`
  }

-  return path
+  return URI.decode(path)
}

But it is a waste of computing power.

ArmorDarks avatar Oct 06 '17 15:10 ArmorDarks