Skip to content
Merged
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
18 changes: 18 additions & 0 deletions src/sed/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,11 @@ fn compile_text_command_posix(
break;
}
}

if text.is_empty() {
compilation_error(lines, line, "incomplete command")?;
}

cmd.data = CommandData::Text(Rc::from(text));
Ok(CommandHandling::Continue)
}
Expand Down Expand Up @@ -2720,6 +2725,19 @@ mod tests {
}
}

#[test]
fn test_compile_text_command_posix_incomplete() {
let (mut lines, mut chars) = make_providers("i\\");
let mut cmd = Command::default();
let mut context = ProcessingContext {
posix: true,
..Default::default()
};
let result = compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context);
let err = result.unwrap_err().to_string();
assert!(err.contains("incomplete command"));
}

#[test]
fn test_compile_text_command_gnu_optional_backslash() {
let mut chars = make_char_provider("athere");
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_sed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,15 @@ fn test_undefined_label() {
.stderr_is("sed: <script argument 1>:1:1: error: undefined label `foo'\n");
}

#[test]
fn test_incomplete_test_command_posix() {
new_ucmd!()
.args(&["--posix", "i\\"])
.fails()
.code_is(1)
.stderr_is("sed: :0:3: error: incomplete command\n");
}

#[test]
fn test_addr0_non_posix() {
new_ucmd!()
Expand Down
Loading