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

url.pathToFileURL doesn't generate valid URLs for UNC paths #34736

Closed
mceachen opened this issue Aug 11, 2020 · 7 comments
Closed

url.pathToFileURL doesn't generate valid URLs for UNC paths #34736

mceachen opened this issue Aug 11, 2020 · 7 comments
Labels
confirmed-bug Issues with confirmed bugs. good first issue Issues that are suitable for first-time contributors. url Issues and PRs related to the legacy built-in url module. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Comments

@mceachen
Copy link
Contributor

  • Node.js version: v12.18.3 and v14.8.0

  • Platform: Windows 10 (10.0.19041)

  • Subsystem: url

What steps will reproduce the bug?

const url = require("url")
url.pathToFileURL("\\\\laptop\\My Documents\\FileSchemeURIs.doc")

Expected behavior

As per Microsoft's UNC URI documentation):

file://laptop/My%20Documents/FileSchemeURIs.doc

Actual behavior

URL {
  href: 'file:///laptop/My%20Documents/FileSchemeURIs.doc',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '/laptop/My%20Documents/FileSchemeURIs.doc',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
  1. hostname should be laptop (not '').

  2. pathname should be /My%20Documents/FileSchemeURIs.doc (not be prefixed by /laptop/).

@guybedford
Copy link
Contributor

This sounds like a valid bug to me. The implementation is at https://github.com/nodejs/node/blob/master/lib/internal/url.js#L1368 where it seems clear this isn't properly being taken into account.

@guybedford guybedford added confirmed-bug Issues with confirmed bugs. good first issue Issues that are suitable for first-time contributors. labels Aug 11, 2020
@jasnell jasnell added url Issues and PRs related to the legacy built-in url module. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Aug 11, 2020
@mceachen
Copy link
Contributor Author

I'd be happy to swing at it, I haven't committed to node yet.

@guybedford
Copy link
Contributor

That would be really great, please feel free if you can. I believe that on posix machines such a path should be ignored, like for other path functions I believe. Building for Windows is documented at https://github.com/nodejs/node/blob/master/BUILDING.md#windows.

@mceachen
Copy link
Contributor Author

(interestingly enough, fileURLToPath already behaves correctly)

@mceachen
Copy link
Contributor Author

Do you want pathToFileURL to throw a new error code for invalid UNC paths (for example, when the path is missing like \\invalid?)

@jasnell
Copy link
Member

jasnell commented Aug 11, 2020

Shouldn't need a new error code. Using one like ERR_INVALID_ARG_VALUE should work for that.

@guybedford
Copy link
Contributor

I'm not sure what would be best - I don't think we currently do path validations, but if there is no adequate URL representation that would support fileURLToPath as its converse it likely makes sense to.

@Trott Trott closed this as completed in 7b8c6b0 Aug 14, 2020
MylesBorins pushed a commit that referenced this issue Aug 17, 2020
Fixes: #34736

PR-URL: #34743
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BethGriggs pushed a commit that referenced this issue Aug 20, 2020
Fixes: #34736

PR-URL: #34743
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
addaleax pushed a commit that referenced this issue Sep 22, 2020
Fixes: #34736

PR-URL: #34743
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
addaleax pushed a commit that referenced this issue Sep 22, 2020
Fixes: #34736

PR-URL: #34743
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. good first issue Issues that are suitable for first-time contributors. url Issues and PRs related to the legacy built-in url module. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants