Skip to content

Commit 4c53044

Browse files
committed
Minimal fix for the high-severity issue without bumping MSRV
Ref: GHSA-r7qv-8r2h-pg27
1 parent fde8a71 commit 4c53044

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shlex"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
authors = [
55
"comex <[email protected]>",
66

src/bytes.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ pub fn quote(in_bytes: &[u8]) -> Cow<[u8]> {
170170
b"\"\""[..].into()
171171
} else if in_bytes.iter().any(|c| match *c as char {
172172
'|' | '&' | ';' | '<' | '>' | '(' | ')' | '$' | '`' | '\\' | '"' | '\'' | ' ' | '\t' |
173-
'\r' | '\n' | '*' | '?' | '[' | '#' | '~' | '=' | '%' => true,
173+
'\r' | '\n' | '*' | '?' | '[' | '#' | '~' | '=' | '%' | '{' | '}' |
174+
'\u{80}' ..= '\u{10ffff}' => true,
174175
_ => false
175176
}) {
176177
let mut out: Vec<u8> = Vec::new();
@@ -200,8 +201,11 @@ pub fn join<'a, I: core::iter::IntoIterator<Item = &'a [u8]>>(words: I) -> Vec<u
200201

201202
#[cfg(test)]
202203
const INVALID_UTF8: &[u8] = b"\xa1";
204+
#[cfg(test)]
205+
const INVALID_UTF8_DOUBLEQUOTED: &[u8] = b"\"\xa1\"";
203206

204207
#[test]
208+
#[allow(invalid_from_utf8)]
205209
fn test_invalid_utf8() {
206210
// Check that our test string is actually invalid UTF-8.
207211
assert!(core::str::from_utf8(INVALID_UTF8).is_err());
@@ -255,7 +259,7 @@ fn test_quote() {
255259
assert_eq!(quote(b"foo bar"), &b"\"foo bar\""[..]);
256260
assert_eq!(quote(b"\""), &b"\"\\\"\""[..]);
257261
assert_eq!(quote(b""), &b"\"\""[..]);
258-
assert_eq!(quote(INVALID_UTF8), INVALID_UTF8);
262+
assert_eq!(quote(INVALID_UTF8), INVALID_UTF8_DOUBLEQUOTED);
259263
}
260264

261265
#[test]
@@ -264,5 +268,5 @@ fn test_join() {
264268
assert_eq!(join(vec![&b""[..]]), &b"\"\""[..]);
265269
assert_eq!(join(vec![&b"a"[..], &b"b"[..]]), &b"a b"[..]);
266270
assert_eq!(join(vec![&b"foo bar"[..], &b"baz"[..]]), &b"\"foo bar\" baz"[..]);
267-
assert_eq!(join(vec![INVALID_UTF8]), INVALID_UTF8);
271+
assert_eq!(join(vec![INVALID_UTF8]), INVALID_UTF8_DOUBLEQUOTED);
268272
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn test_quote() {
146146
assert_eq!(quote("foo bar"), "\"foo bar\"");
147147
assert_eq!(quote("\""), "\"\\\"\"");
148148
assert_eq!(quote(""), "\"\"");
149+
assert_eq!(quote("{foo,bar}"), "\"{foo,bar}\"");
149150
}
150151

151152
#[test]

0 commit comments

Comments
 (0)