mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 08:36:54 +00:00
fix(window): Compatible with Windows Path (#2691)
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -90,7 +90,12 @@ pub fn retain_slash(s: &str) -> String {
|
||||
|
||||
/// Checks if string `s` starts with `prefix` using case-insensitive comparison.
|
||||
pub fn strings_has_prefix_fold(s: &str, prefix: &str) -> bool {
|
||||
s.len() >= prefix.len() && (s[..prefix.len()] == *prefix || s[..prefix.len()].eq_ignore_ascii_case(prefix))
|
||||
if s.starts_with(prefix) {
|
||||
return true;
|
||||
}
|
||||
|
||||
s.get(..prefix.len())
|
||||
.is_some_and(|s_prefix| s_prefix.eq_ignore_ascii_case(prefix))
|
||||
}
|
||||
|
||||
/// Checks if string `s` starts with `prefix`.
|
||||
@@ -875,4 +880,16 @@ mod tests {
|
||||
assert_eq!(bucket, "bucket");
|
||||
assert_eq!(object, "object");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "windows")]
|
||||
fn test_path_to_bucket_object_with_base_path_handles_unicode_without_panicking() {
|
||||
let (bucket, object) = path_to_bucket_object_with_base_path(
|
||||
"D:\\Github\\rustfs\\target\\volumes\\test1",
|
||||
"s3-test-bucket/中文/日本語/한글-9cd5599a-f8eb-4e24-9df7-32ecd8d8ad1f",
|
||||
);
|
||||
|
||||
assert_eq!(bucket, "s3-test-bucket");
|
||||
assert_eq!(object, "中文/日本語/한글-9cd5599a-f8eb-4e24-9df7-32ecd8d8ad1f");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,13 +506,12 @@ pub fn parse_ellipses_range(pattern: &str) -> Result<Vec<String>> {
|
||||
/// ```
|
||||
///
|
||||
pub fn strings_has_prefix_fold(s: &str, prefix: &str) -> bool {
|
||||
if s.len() < prefix.len() {
|
||||
return false;
|
||||
if s.starts_with(prefix) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let s_prefix = &s[..prefix.len()];
|
||||
// Test match with case first, then case-insensitive
|
||||
s_prefix == prefix || s_prefix.to_lowercase() == prefix.to_lowercase()
|
||||
s.get(..prefix.len())
|
||||
.is_some_and(|s_prefix| s_prefix.eq_ignore_ascii_case(prefix))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -872,4 +871,13 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "windows")]
|
||||
fn test_strings_has_prefix_fold_handles_unicode_without_panicking() {
|
||||
assert!(!strings_has_prefix_fold(
|
||||
"s3-test-bucket/中文/日本語/한글-9cd5599a-f8eb-4e24-9df7-32ecd8d8ad1f",
|
||||
"D:\\Github\\rustfs\\target\\volumes\\test1",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user