Disallow ':' in `PathBuf` guard on Windows.

Fixes #1949.
This commit is contained in:
Sergio Benitez 2022-04-18 18:27:41 -07:00
parent 1b37d571c2
commit ccf0b802bc
1 changed files with 7 additions and 3 deletions

View File

@ -172,7 +172,7 @@ impl<'a> Segments<'a, Path> {
/// * Decoded segment starts with any of: `*`
/// * Decoded segment ends with any of: `:`, `>`, `<`
/// * Decoded segment contains any of: `/`
/// * On Windows, decoded segment contains any of: `\`
/// * On Windows, decoded segment contains any of: `\`, `:`
/// * Percent-encoding results in invalid UTF-8.
///
/// Additionally, if `allow_dotfiles` is `false`, an `Err` is returned if
@ -215,8 +215,12 @@ impl<'a> Segments<'a, Path> {
return Err(PathError::BadEnd('<'))
} else if segment.contains('/') {
return Err(PathError::BadChar('/'))
} else if cfg!(windows) && segment.contains('\\') {
return Err(PathError::BadChar('\\'))
} else if cfg!(windows) {
if segment.contains('\\') {
return Err(PathError::BadChar('\\'))
} else if segment.contains(':') {
return Err(PathError::BadChar(':'))
}
} else {
buf.push(&*segment)
}