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

Support UNC path beginning with double slashes #38

Merged
merged 3 commits into from
Oct 6, 2020

Conversation

MurakamiShinyu
Copy link
Contributor

@MurakamiShinyu MurakamiShinyu commented Aug 3, 2020

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 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 version normalizeSafe() to preserve leading double slashes. (Update: same for joinSafe())


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.

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 .
@MurakamiShinyu MurakamiShinyu marked this pull request as draft August 4, 2020 03:31
@MurakamiShinyu MurakamiShinyu marked this pull request as ready for review August 4, 2020 03:59
@anodynos anodynos self-assigned this Sep 23, 2020
@anodynos
Copy link
Owner

Thank you for the PR @MurakamiShinyu & the tests. I will have a thorough look when I find some time ;-)

@anodynos anodynos merged commit d748cf5 into anodynos:master Oct 6, 2020
@anodynos
Copy link
Owner

anodynos commented Oct 6, 2020

Thank you @MurakamiShinyu - I will publish as 2.0.0 just in case it represents breaking changes for some people ;-)

@anodynos anodynos mentioned this pull request Oct 6, 2020
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants