Preserve the leading slashes of Windows UNC paths - #17
Open
Eljees wants to merge 1 commit into
Open
Conversation
`normalize()` collapses the leading double backslash of a plain UNC path, so `\\server\share\file.css` becomes `/server/share/file.css` and the path loses its network-path identity. The Win32 namespace prefixes (`\\?\`, `\\.\`) are already special-cased to keep their doubled leading slash; this applies the same treatment to plain UNC paths. Forward-slash inputs like `//foo/bar` are intentionally left unchanged (still collapse to `/foo/bar`), matching the existing test expectations, since a leading double slash is only meaningful on Windows input paths spelled with backslashes. Downstream context: stylelint/stylelint#3045 (files addressed via a UNC path silently produce no lint results, because the collapsed path no longer matches anything when handed to fast-glob). Signed-off-by: Eljees <3.14hell@gmail.com>
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.
Problem
A plain Windows UNC path loses its leading double slash:
The leading
\\is treated as a repeated separator and collapsed, so theresult no longer refers to a network path. The Win32 namespace prefixes are
already special-cased (
\\?\C:\...->//?/C:/...,\\.\CdRomX->//./CdRomX); a plain UNC path is the one Windows form that loses itsdoubled leading slash.
Change
After the existing namespace-prefix handling, keep the
//prefix when theinput starts with exactly two backslashes followed by a path character. Two
notes on scope:
//foo/bar) are intentionally NOT changed and stillcollapse to
/foo/bar, exactly as the existing tests specify - a doubledleading slash is only unambiguous on backslash-spelled Windows paths.
current collapsing behaviour.
Tests
5 new assertions (plain UNC, admin share
c$, trailing-slash stripping andstripTrailing: false). Full suite: 34 passing before, 39 passing after,0 failing; all pre-existing expectations untouched.
Downstream context
This is the root cause of stylelint/stylelint#3045 (linting a file addressed
via a UNC path silently reports no results): stylelint normalizes the entry
before handing it to fast-glob, and the collapsed
/server/share/...nolonger matches the file. A stylelint maintainer asked whether this could be
fixed upstream here rather than worked around there
(stylelint/stylelint#3045 (comment)).
Verified end to end on a real Windows host: with this patch dropped into
stylelint's
node_modules, stylelint's UNC reproducer(
\\localhost\<drive>$\...) lints correctly with no changes on thestylelint side; with the unpatched file it fails.