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
8 changes: 8 additions & 0 deletions src/sed/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,10 @@ fn compile_subst_command(
) -> UResult<CommandHandling> {
line.advance(); // move past 's'

if line.eol() {
return compilation_error(lines, line, "unterminated `s' command");
}

let delimiter = line.current();
if delimiter == '\0' || delimiter == '\\' {
return compilation_error(
Expand Down Expand Up @@ -907,6 +911,10 @@ fn compile_trans_command(
) -> UResult<CommandHandling> {
line.advance(); // move past 'y'

if line.eol() {
return compilation_error(lines, line, "unterminated `y' command");
}

let delimiter = line.current();
if delimiter == '\0' || delimiter == '\\' {
return compilation_error(
Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_sed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2937,6 +2937,25 @@ fn test_comma_without_second_address() {
}
}

#[test]
fn test_unterminated_s_or_y_command() {
for (script, column, command) in [
("s", 2, 's'),
("1s", 3, 's'),
("p;s", 4, 's'),
("y", 2, 'y'),
("{y", 3, 'y'),
] {
new_ucmd!()
.args(&[script])
.fails()
.code_is(1)
.stderr_is(format!(
"sed: <script argument 1>:1:{column}: error: unterminated `{command}' command\n"
));
}
}

// The following test diverse ways in which regexes are matched.
// Search for 'regex\.' to find them in the code.
#[test]
Expand Down
Loading