diff --git a/src/sed/compiler.rs b/src/sed/compiler.rs index 02184fb2..4a59eeb5 100644 --- a/src/sed/compiler.rs +++ b/src/sed/compiler.rs @@ -841,6 +841,10 @@ fn compile_subst_command( ) -> UResult { 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( @@ -907,6 +911,10 @@ fn compile_trans_command( ) -> UResult { 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( diff --git a/tests/by-util/test_sed.rs b/tests/by-util/test_sed.rs index 12f7f265..7216d4e0 100644 --- a/tests/by-util/test_sed.rs +++ b/tests/by-util/test_sed.rs @@ -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: