path: fix normalization of Windows device paths missing colon#61545
Open
HassanFleyah wants to merge 3 commits intonodejs:mainfrom
Open
path: fix normalization of Windows device paths missing colon#61545HassanFleyah wants to merge 3 commits intonodejs:mainfrom
HassanFleyah wants to merge 3 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
There was a problem hiding this comment.
Pull request overview
This PR tightens path.win32.normalize() handling for Windows device paths so that reserved device names prefixed with \\.\ or \\?\ are correctly detected even when the trailing colon is missing. It aims to close an edge case where such paths could bypass existing normalization logic.
Changes:
- Refactors the UNC/device-root detection branch in
win32.normalize()to special-casefirstPart === '.' || firstPart === '?'for device roots. - Adds new logic to detect reserved device names when a
\\.\or\\?\namespace prefix is present but the path lacks a colon, usingWINDOWS_RESERVED_NAMESdirectly on the substring after the prefix.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
This PR fixes an inconsistency in
path.win32.normalize()where Windows reserved device names prefixed with\\.\or\\?\were not being correctly detected if they lacked a trailing colon.Current behavior:
path.normalize('\\\\.\\CON:')-> Correctly handled/sanitized.path.normalize('\\\\.\\CON')-> Returned as-is (Inconsistent).This change ensures that
\\.\CONand\\?\CONare treated consistently with other device paths by strictly checking against the reserved names list when the namespace prefix is present but the colon is missing.Context
This addresses an edge case where valid Windows device paths bypass normalization logic due to the missing colon expectation.
Testing
I have verified this fix locally.