]> Cypherpunks.ru repositories - gostls13.git/commit
path/filepath: detect all forms of \\ volume paths on Windows
authorDamien Neil <dneil@google.com>
Wed, 19 Oct 2022 21:41:03 +0000 (14:41 -0700)
committerDamien Neil <dneil@google.com>
Wed, 9 Nov 2022 22:06:00 +0000 (22:06 +0000)
commitbe9d78c9c5905fbc10d8cd6a4714dd4ad1c91674
treea512b557f9b117dbfbf5ab027268e7a304131d9c
parent575964d42c7b3001c09f2676d0ee9d520debb5eb
path/filepath: detect all forms of \\ volume paths on Windows

Previously, the volumeNameLen function checked for UNC paths starting
with two slashes, a non-'.' character, and another slash. This misses
volume names such as "\\.\C:\".

The previous check for volume names rejects paths beginning
with "\\.". This is incorrect, because while these names are not
UNC paths, "\\.\C:\" is a DOS device path prefix indicating the
C: device. It also misses UNC path prefixes in the form
"\\.\UNC\server\share\".

The previous check for UNC paths also rejects any path with an
empty or missing host or share component. This leads to a number
of possibly-incorrect behaviors, such as Clean(`\\a`) returning `\a`.
Converting the semantically-significant `\\` prefix to a single `\`
seems wrong.

Consistently treat paths beginning with two separators as having
a volume prefix.

Update VolumeName to detect DOS device paths (`\\.\` or `\\?\`),
DOS device paths linking to UNC paths (`\\.\UNC\Server\Share`
or `\\?\UNC\Server\Share`), and UNC paths (`\\Server\Share\`).

Clean(`\\a`) = `\\a`
Join(`\\`, `a`, `b`) = `\\a\b`

In addition, normalize path separators in VolumeName for consistency
with other functions which Clean their result.

Fixes #56336

Change-Id: Id01c33029585bfffc313dcf0ad42ff6ac7ce42fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/444280
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
src/path/filepath/path.go
src/path/filepath/path_test.go
src/path/filepath/path_windows.go
src/path/filepath/path_windows_test.go