From 3c5018bd6bd0d8e2dc7cf3aa81781b82a36d2ee1 Mon Sep 17 00:00:00 2001 From: Gwen Lg Date: Mon, 16 Feb 2026 15:09:03 +0100 Subject: [PATCH] refactor: use str trim result to parse xml - use `trim` method of `str` instead of manual implementation with `trim_matches(char::is_whitespace)` - use result of `trim` for xml parsing instead of use the `str` before trim. --- src/api/s3/bucket.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/s3/bucket.rs b/src/api/s3/bucket.rs index 4abc614f..901961e9 100644 --- a/src/api/s3/bucket.rs +++ b/src/api/s3/bucket.rs @@ -330,8 +330,8 @@ fn parse_create_bucket_xml(xml_bytes: &[u8]) -> Option> { // Returns Some(None) if no location constraint is given // Returns Some(Some("xxxx")) where xxxx is the given location constraint - let xml_str = std::str::from_utf8(xml_bytes).ok()?; - if xml_str.trim_matches(char::is_whitespace).is_empty() { + let xml_str = std::str::from_utf8(xml_bytes).ok()?.trim(); + if xml_str.is_empty() { return Some(None); } @@ -373,6 +373,7 @@ mod tests { #[test] fn create_bucket() { assert_eq!(parse_create_bucket_xml(br#""#), Some(None)); + assert_eq!(parse_create_bucket_xml(br#" "#), Some(None)); assert_eq!( parse_create_bucket_xml( br#"