mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
tr: forbid non-numeric repeat counts
This commit is contained in:
parent
0bf5a68c54
commit
e53dd5ffe1
2 changed files with 19 additions and 3 deletions
|
@ -8,8 +8,8 @@
|
||||||
use crate::unicode_table;
|
use crate::unicode_table;
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{tag, take},
|
bytes::complete::{tag, take, take_till},
|
||||||
character::complete::{digit1, one_of},
|
character::complete::one_of,
|
||||||
combinator::{map, map_opt, peek, recognize, value},
|
combinator::{map, map_opt, peek, recognize, value},
|
||||||
multi::{many0, many_m_n},
|
multi::{many0, many_m_n},
|
||||||
sequence::{delimited, preceded, separated_pair},
|
sequence::{delimited, preceded, separated_pair},
|
||||||
|
@ -404,7 +404,14 @@ impl Sequence {
|
||||||
fn parse_char_repeat(input: &[u8]) -> IResult<&[u8], Result<Self, BadSequence>> {
|
fn parse_char_repeat(input: &[u8]) -> IResult<&[u8], Result<Self, BadSequence>> {
|
||||||
delimited(
|
delimited(
|
||||||
tag("["),
|
tag("["),
|
||||||
separated_pair(Self::parse_backslash_or_char, tag("*"), digit1),
|
separated_pair(
|
||||||
|
Self::parse_backslash_or_char,
|
||||||
|
tag("*"),
|
||||||
|
// TODO
|
||||||
|
// Why are the opening and closing tags not sufficient?
|
||||||
|
// Backslash check is a workaround for `check_against_gnu_tr_tests_repeat_bs_9`
|
||||||
|
take_till(|ue| matches!(ue, b']' | b'\\')),
|
||||||
|
),
|
||||||
tag("]"),
|
tag("]"),
|
||||||
)(input)
|
)(input)
|
||||||
.map(|(l, (c, cnt_str))| {
|
.map(|(l, (c, cnt_str))| {
|
||||||
|
|
|
@ -1512,3 +1512,12 @@ fn test_backwards_range() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_non_digit_repeat() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["a", "[b*c]"])
|
||||||
|
.pipe_in("")
|
||||||
|
.fails()
|
||||||
|
.stderr_only("tr: invalid repeat count 'c' in [c*n] construct\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue