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
2 changes: 1 addition & 1 deletion docs/src/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/sed/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/by-util/test_sed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
Expand Down
Loading