Support UNC path beginning with double slashes#38
Merged
anodynos merged 3 commits intoanodynos:masterfrom Oct 6, 2020
Merged
Conversation
Replacing double slashes '//' to '/' in `toUnix()` causes problem when the path is a UNC path, beginning with double (back)slashes.
Examples of such pathes:
```
'\\\\server\\share\\file': '//server/share/file'
'\\\\?\\UNC\\server\\share\\file': '//?/UNC/server/share/file'
'\\\\LOCALHOST\\c$\\temp\\file': '//LOCALHOST/c$/temp/file'
'\\\\?\\c:\\temp\\file': '//?/c:/temp/file'
'\\\\.\\c:\\temp\\file': '//./c:/temp/file'
'////\\.\\c:/temp\\//file': '//./c:/temp/file'
```
See the following Microsoft documents about Windows path names:
https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
Now (with my previous commit) returns '//server/share/file' on Windows but returns '/server/share/file' on Unix. I think this behavior is good in most case, but may be problematic when processing Windows UNC paths on Unix. So this commit modifies only the safe version .
Owner
|
Thank you for the PR @MurakamiShinyu & the tests. I will have a thorough look when I find some time ;-) |
Owner
|
Thank you @MurakamiShinyu - I will publish as 2.0.0 just in case it represents breaking changes for some people ;-) |
Closed
1 task
MurakamiShinyu
added a commit
to MurakamiShinyu/upath
that referenced
this pull request
May 16, 2022
This is a follow-up fix to anodynos#38. That was my mistake. The regexp lookbehind assertion `(?<!^)` is not supported in some JavaScript engines, esp. WebKit's, and causes error, so it should not be used yet. See - "lookbehind assertions" in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility - WebKit issue: [Bug 174931 - Implement RegExp lookbehind assertions](https://bugs.webkit.org/show_bug.cgi?id=174931)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replacing double slashes '//' to '/' in
toUnix()causes problem when the path is a UNC path, beginning with double (back)slashes.Examples of such pathes:
See the following Microsoft documents about Windows path names:
https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
Now (with the modified version of
toUnix()),upath.normalize('\\\\server\\share\\file')returns '//server/share/file' on Windows but returns '/server/share/file' on Unix. I think this behavior is good in most case, but may be problematic when processing Windows UNC paths on Unix. So I modified the safe versionnormalizeSafe()to preserve leading double slashes. (Update: same forjoinSafe())I noticed a related pull request #37 . Maybe it is good to omit unnecessary
//?/prefix. However, we need to keep the leading double slashes of the UNC paths.