1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #8158 from tgrez/main

expr: fix substr parsing
This commit is contained in:
Daniel Hofstetter 2025-06-12 10:41:59 +02:00 committed by GitHub
commit 3a087aa4f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View file

@ -685,9 +685,9 @@ impl<'a, S: AsRef<str>> Parser<'a, S> {
}
}
"substr" => {
let string = self.parse_expression()?;
let pos = self.parse_expression()?;
let length = self.parse_expression()?;
let string = self.parse_simple_expression()?;
let pos = self.parse_simple_expression()?;
let length = self.parse_simple_expression()?;
AstNodeInner::Substr {
string: Box::new(string),
pos: Box::new(pos),

View file

@ -507,6 +507,19 @@ fn test_substr() {
.stderr_only("expr: syntax error: unexpected argument 'substr'\n");
}
#[test]
fn test_substr_precedence() {
new_ucmd!()
.args(&["substr", "ab cd", "3", "1", "!=", " "])
.fails_with_code(1)
.stdout_only("0\n");
new_ucmd!()
.args(&["substr", "ab cd", "2", "1", "!=", " "])
.succeeds()
.stdout_only("1\n");
}
#[test]
fn test_invalid_substr() {
new_ucmd!()