chore: Bug fix: non-canonical path detection when MAIN_SEPARATOR is not slash or occurs twice in a row

This commit is contained in:
Chris Hennick 2024-05-03 14:34:05 -07:00
parent 5cd448802f
commit 0fe12b2ec9
No known key found for this signature in database
GPG key ID: DA47AABA4961C509

View file

@ -220,7 +220,9 @@ pub(crate) fn path_to_string<T: AsRef<Path>>(path: T) -> String {
let mut maybe_original = None; let mut maybe_original = None;
if let Some(original) = path.as_ref().to_str() { if let Some(original) = path.as_ref().to_str() {
if (MAIN_SEPARATOR == '/' || !original.contains(MAIN_SEPARATOR)) if (MAIN_SEPARATOR == '/' || !original.contains(MAIN_SEPARATOR))
&& !original.ends_with('.') && !original.contains("./") { && !original.ends_with('.')
&& !original.contains([MAIN_SEPARATOR, MAIN_SEPARATOR])
&& !original.contains(['.', MAIN_SEPARATOR]) {
if original.starts_with(MAIN_SEPARATOR) { if original.starts_with(MAIN_SEPARATOR) {
maybe_original = Some(&original[1..]); maybe_original = Some(&original[1..]);
} else { } else {