unshiftio / url-parse

Small footprint URL parser that works seamlessly across Node.js and browser environments.
http://unshift.io
MIT License
1.03k stars 104 forks source link

Sanitize only special URLs #209

Closed lpinca closed 3 years ago

lpinca commented 3 years ago

Fixes https://github.com/unshiftio/url-parse/pull/208#discussion_r675788224.

enahum commented 3 years ago

this is causing issues. let's say I have a path file:://file-path/file.png after parsing the href prop is returning file:///file-path/file.png notice the third slash after the protocol.

lpinca commented 3 years ago

@enahum I see that the Node.js URL parser handles this differently

new URL('file://file-path/file')
URL {
  href: 'file://file-path/file',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: 'file-path',
  hostname: 'file-path',
  port: '',
  pathname: '/file',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

but the issue it not caused by this commit. This behavior was introduced with d2979b586d8c7751e0c77f127d9ce1b2143cc0c9. I'll see if I can fix it.

lpinca commented 3 years ago

Anyway this is kind of funny:

> new URL('file:file-path/file')
URL {
  href: 'file:///file-path/file',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '/file-path/file',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
> new URL('file:/file-path/file')
URL {
  href: 'file:///file-path/file',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '/file-path/file',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
> new URL('file://file-path/file')
URL {
  href: 'file://file-path/file',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: 'file-path',
  hostname: 'file-path',
  port: '',
  pathname: '/file',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
> new URL('file:///file-path/file')
URL {
  href: 'file:///file-path/file',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '/file-path/file',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

I wonder if a file: url can have a host.

lpinca commented 3 years ago

@enahum https://github.com/unshiftio/url-parse/pull/210 should fix the issue.

3rd-Eden commented 3 years ago

Published as 1.5.3