From 3ab253ad591851dcf2bdc2ccacc619ed1acf6e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Arda=20G=C3=BCney?= <64425746+yunusarda-sudo@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:10:17 +0300 Subject: [PATCH] sed: allow one address for q, and for l with --posix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yunus Arda Güney <64425746+yunusarda-sudo@users.noreply.github.com> --- docs/src/extensions.md | 2 +- src/sed/compiler.rs | 4 ++-- tests/by-util/test_sed.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/src/extensions.md b/docs/src/extensions.md index 67360098..4c79de7d 100644 --- a/docs/src/extensions.md +++ b/docs/src/extensions.md @@ -16,7 +16,7 @@ Below is a list of these extensions and incompatibilities. * The `a`, `c`, and `i` commands do not require an initial backslash, allow text to appear on the same line, and support escape sequences in the specified text. -* The `a`, `i`, `=`, `l`, `q` and `r` commands support address range as an extension to POSIX. +* The `a`, `i`, `=`, `l` and `r` commands support address range as an extension to POSIX. * The substitution command replacement group `\0` is a synonym for &. * An `F` command outputs the name of the file currently being processed. * A `Q` command (optionally followed by an exit code) quits immediately. diff --git a/src/sed/compiler.rs b/src/sed/compiler.rs index 5c68db21..5b7f2677 100644 --- a/src/sed/compiler.rs +++ b/src/sed/compiler.rs @@ -1806,11 +1806,11 @@ fn get_cmd_spec( handler: compile_empty_command, }), 'l' => Ok(CommandSpec { - n_addr: 2, + n_addr: if posix { 1 } else { 2 }, handler: compile_number_command, }), 'q' => Ok(CommandSpec { - n_addr: if posix { 1 } else { 2 }, + n_addr: 1, handler: compile_number_command, }), // Q is a GNU extension diff --git a/tests/by-util/test_sed.rs b/tests/by-util/test_sed.rs index ba5bdc9d..ffff1894 100644 --- a/tests/by-util/test_sed.rs +++ b/tests/by-util/test_sed.rs @@ -1261,6 +1261,34 @@ fn test_posix_disables_gnu_bre_operators() { .stdout_is("a\nb\n"); } +#[test] +fn test_q_takes_one_address() { + for script in ["2,3q", "2,3Q"] { + new_ucmd!() + .args(&[script]) + .fails_with_code(1) + .stderr_contains("expects up to 1 address(es), found 2"); + } + new_ucmd!() + .args(&["2q"]) + .pipe_in("k\nl\nm\n") + .succeeds() + .stdout_is("k\nl\n"); +} + +#[test] +fn test_posix_l_takes_one_address() { + new_ucmd!() + .args(&["--posix", "-n", "2,3l"]) + .fails_with_code(1) + .stderr_contains("command l expects up to 1 address(es), found 2"); + new_ucmd!() + .args(&["-n", "2,3l"]) + .pipe_in("k\nl\nm\n") + .succeeds() + .stdout_is("l$\nm$\n"); +} + #[test] fn test_posix_disables_gnu_character_classes() { new_ucmd!()