Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/xargs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ where

match (&escape, pending[i]) {
(Some(Escape::Quote(quote)), c) if c == *quote => escape = None,
(Some(Escape::Quote(q)), b'\n') => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Unterminated quote: {q}"),
));
}
(Some(Escape::Quote(_)), c) => result.push(c),
(Some(Escape::Slash), c) => {
result.push(c);
Expand Down
19 changes: 19 additions & 0 deletions tests/test_xargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,25 @@ fn xargs_unterminated_quote() {
.no_stdout();
}

#[test]
fn xargs_quotes_cannot_span_lines() {
let temp_file = tempfile::NamedTempFile::new().unwrap();

for quote in ['\'', '"'] {
std::fs::write(
temp_file.path(),
format!("alpha{quote}beta\ngamma{quote}\n"),
)
.unwrap();

ucmd()
.args(&["-a", &temp_file.path().to_string_lossy()])
.fails_with_code(1)
.stderr_contains("Error: Unterminated quote:")
.no_stdout();
}
}

#[test]
fn xargs_zero_lines() {
ucmd()
Expand Down
Loading