fix(host): require complete UNC forms in the fully-qualified path check

ds-review-bot round 5: '\\' and '\\server' satisfy win32.isAbsolute and
the previous two-separator test, yet resolve() collapses them to
drive-relative roots. The UNC arm now requires server and share components;
incomplete prefixes reject with the business codes, covered per-platform.
This commit is contained in:
creatixchu
2026-07-28 18:27:26 +08:00
parent b211a80b1f
commit 987ecc2ec2
5 changed files with 13 additions and 8 deletions

View File

@@ -38,16 +38,16 @@ function ancestryCrumbs(target: string): DirectoryEntry[] {
/**
* True when the path names one fixed filesystem location regardless of
* process state: POSIX-absolute on POSIX; on Windows only drive-qualified
* (`C:\…`) or UNC (`\\server\…`) forms — rooted drive-less forms (`\foo`,
* `/foo`) pass `isAbsolute` yet still resolve against the process's current
* drive.
* (`C:\…`) or complete UNC (`\\server\share…`) forms. Rooted drive-less
* forms (`\foo`, `/foo`) and incomplete UNC prefixes (`\\`, `\\server`)
* pass `isAbsolute` yet still resolve against the process's current drive.
* @param path - candidate path.
* @param platform - replaces `process.platform` for deterministic tests.
* @returns whether the path is fully qualified on the platform.
*/
export function fullyQualified(path: string, platform: NodeJS.Platform = process.platform): boolean {
return platform === 'win32'
? win32.isAbsolute(path) && /^(?:[A-Za-z]:[\\/]|[\\/]{2})/.test(path)
? win32.isAbsolute(path) && /^(?:[A-Za-z]:[\\/]|[\\/]{2}[^\\/]+[\\/]+[^\\/]+)/.test(path)
: posix.isAbsolute(path)
}