mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Simplify needs_encoding() and add a test
This commit is contained in:
committed by
holger krekel
parent
06bc5513ae
commit
a82f2a5df3
@@ -1130,14 +1130,8 @@ fn encode_words(word: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn needs_encoding(to_check: impl AsRef<str>) -> bool {
|
pub fn needs_encoding(to_check: impl AsRef<str>) -> bool {
|
||||||
let to_check = to_check.as_ref();
|
!to_check.as_ref().chars().all(|c| {
|
||||||
|
c.is_ascii_alphanumeric() || c == '-' || c == '_' || c == '.' || c == '~' || c == '%'
|
||||||
if to_check.is_empty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
to_check.chars().any(|c| {
|
|
||||||
!c.is_ascii_alphanumeric() && c != '-' && c != '_' && c != '.' && c != '~' && c != '%'
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1196,4 +1190,12 @@ mod tests {
|
|||||||
FBQUFBQUFBQQ==";
|
FBQUFBQUFBQQ==";
|
||||||
assert_eq!(wrapped_base64_encode(input), output);
|
assert_eq!(wrapped_base64_encode(input), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_needs_encoding() {
|
||||||
|
assert!(!needs_encoding(""));
|
||||||
|
assert!(!needs_encoding("foobar"));
|
||||||
|
assert!(needs_encoding(" "));
|
||||||
|
assert!(needs_encoding("foo bar"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user