Fix os._volume_name_len to handle paths of purely separators. Also, fix '\h\s' handling

This commit is contained in:
Shane Shrybman
2026-04-09 23:26:37 -04:00
parent c87d1a3cf6
commit f4aa97f89a

View File

@@ -377,17 +377,25 @@ _volume_name_len :: proc(path: string) -> (length: int) {
// UNC path, minimum version of the volume is `\\h\s` for host, share.
// Can also contain an IP address in the host position.
// (path might be purely path separators)
slash_count := 0
found_host: bool
for i in prefix..<len(path) {
// Host needs to be at least 1 character
if _is_path_separator(path[i]) && i > 0 {
if _is_path_separator(path[i]) {
slash_count += 1
if slash_count == 2 {
if slash_count == 2 && found_host {
return i
}
} else {
found_host = true
// Found a host but no trailing slash `\\h\s`
if slash_count == 1 && i == len(path)-1 {
return len(path)
}
}
}
return len(path)
return 0
}