Skip to content

Commit

Permalink
Minimal fix for the high-severity issue without bumping MSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
comex committed Jan 22, 2024
1 parent fde8a71 commit 4c53044
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shlex"
version = "1.2.0"
version = "1.2.1"
authors = [
"comex <comexk@gmail.com>",
"Fenhl <fenhl@fenhl.net>"
Expand Down
10 changes: 7 additions & 3 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ pub fn quote(in_bytes: &[u8]) -> Cow<[u8]> {
b"\"\""[..].into()
} else if in_bytes.iter().any(|c| match *c as char {
'|' | '&' | ';' | '<' | '>' | '(' | ')' | '$' | '`' | '\\' | '"' | '\'' | ' ' | '\t' |
'\r' | '\n' | '*' | '?' | '[' | '#' | '~' | '=' | '%' => true,
'\r' | '\n' | '*' | '?' | '[' | '#' | '~' | '=' | '%' | '{' | '}' |
'\u{80}' ..= '\u{10ffff}' => true,
_ => false
}) {
let mut out: Vec<u8> = Vec::new();
Expand Down Expand Up @@ -200,8 +201,11 @@ pub fn join<'a, I: core::iter::IntoIterator<Item = &'a [u8]>>(words: I) -> Vec<u

#[cfg(test)]
const INVALID_UTF8: &[u8] = b"\xa1";
#[cfg(test)]
const INVALID_UTF8_DOUBLEQUOTED: &[u8] = b"\"\xa1\"";

#[test]
#[allow(invalid_from_utf8)]
fn test_invalid_utf8() {
// Check that our test string is actually invalid UTF-8.
assert!(core::str::from_utf8(INVALID_UTF8).is_err());
Expand Down Expand Up @@ -255,7 +259,7 @@ fn test_quote() {
assert_eq!(quote(b"foo bar"), &b"\"foo bar\""[..]);
assert_eq!(quote(b"\""), &b"\"\\\"\""[..]);
assert_eq!(quote(b""), &b"\"\""[..]);
assert_eq!(quote(INVALID_UTF8), INVALID_UTF8);
assert_eq!(quote(INVALID_UTF8), INVALID_UTF8_DOUBLEQUOTED);
}

#[test]
Expand All @@ -264,5 +268,5 @@ fn test_join() {
assert_eq!(join(vec![&b""[..]]), &b"\"\""[..]);
assert_eq!(join(vec![&b"a"[..], &b"b"[..]]), &b"a b"[..]);
assert_eq!(join(vec![&b"foo bar"[..], &b"baz"[..]]), &b"\"foo bar\" baz"[..]);
assert_eq!(join(vec![INVALID_UTF8]), INVALID_UTF8);
assert_eq!(join(vec![INVALID_UTF8]), INVALID_UTF8_DOUBLEQUOTED);
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fn test_quote() {
assert_eq!(quote("foo bar"), "\"foo bar\"");
assert_eq!(quote("\""), "\"\\\"\"");
assert_eq!(quote(""), "\"\"");
assert_eq!(quote("{foo,bar}"), "\"{foo,bar}\"");
}

#[test]
Expand Down

0 comments on commit 4c53044

Please sign in to comment.