Skip to content

Commit 32bfcbc

Browse files
Slight refactor of escape.
Signed-off-by: Aalekh Patel <aalekh@protectchildren.ca>
1 parent 3fa01c2 commit 32bfcbc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/escape.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ fn whitelisted(byte: u8) -> bool {
2828
/// [`shell-escape::unix::escape`]: https://docs.rs/shell-escape/latest/src/shell_escape/lib.rs.html#101
2929
///
3030
pub fn escape(s: &OsStr) -> Cow<'_, OsStr> {
31-
let s = s.as_bytes();
32-
let all_whitelisted = s.iter().copied().all(whitelisted);
31+
let as_bytes = s.as_bytes();
32+
let all_whitelisted = as_bytes.iter().copied().all(whitelisted);
3333

34-
if !s.is_empty() && all_whitelisted {
34+
if !as_bytes.is_empty() && all_whitelisted {
3535
return Cow::Borrowed(s);
3636
}
3737

38-
let mut escaped = Vec::with_capacity(s.len() + 2);
38+
let mut escaped = Vec::with_capacity(as_bytes.len() + 2);
3939
escaped.reserve(4);
4040
escaped.push(b'\'');
4141

42-
for &b in s {
42+
for &b in as_bytes {
4343
match b {
4444
b'\'' | b'!' => {
4545
escaped.push(b'\'');
@@ -110,4 +110,4 @@ mod tests {
110110
&[b'\'', 0x66, 0x6f, 0x80, 0x6f, b'\'']
111111
);
112112
}
113-
}
113+
}

0 commit comments

Comments
 (0)