diff --git a/src/sed/processor.rs b/src/sed/processor.rs index 298a974e..2be7579f 100644 --- a/src/sed/processor.rs +++ b/src/sed/processor.rs @@ -567,9 +567,7 @@ fn list( ) -> UResult<()> { // Special case for an empty pattern space if line.is_empty() { - if line.is_newline_terminated() { - output.write_str("$\n")?; - } + output.write_str("$\n")?; return Ok(()); } diff --git a/tests/by-util/test_sed.rs b/tests/by-util/test_sed.rs index 5597d2fe..581c9b71 100644 --- a/tests/by-util/test_sed.rs +++ b/tests/by-util/test_sed.rs @@ -2270,6 +2270,17 @@ fn list_invalid_utf8_byte_locale() { .stdout_is_bytes(b"\\351$\n"); } +/// `l` shows an empty pattern space as `$`, even when the line lacked a +/// newline, as GNU sed does. +#[test] +fn list_empty_line_without_newline() { + new_ucmd!() + .args(&["-n", "s/a//;l"]) + .pipe_in("a") + .succeeds() + .stdout_is("$\n"); +} + //////////////////////////////////////////////////////////// // In-place editing #[test]