1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #5673 from tertsdiepraam/expr-fix-comparison

`expr`: coerce to string before comparing values
This commit is contained in:
Sylvestre Ledru 2023-12-18 22:50:42 +01:00 committed by GitHub
commit 52af36d80b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -70,6 +70,8 @@ impl RelationOp {
}
} else {
// These comparisons should be using locale settings
let a = a.eval_as_string();
let b = b.eval_as_string();
match self {
Self::Lt => a < b,
Self::Leq => a <= b,
@ -195,7 +197,7 @@ const PRECEDENCE: &[&[(&str, BinOp)]] = &[
&[(":", BinOp::String(StringOp::Match))],
];
#[derive(Debug, PartialEq, Eq, Ord, PartialOrd)]
#[derive(Debug)]
pub enum NumOrStr {
Num(BigInt),
Str(String),

View file

@ -362,3 +362,11 @@ fn test_invalid_syntax() {
.stderr_contains("syntax error");
}
}
#[test]
fn test_num_str_comparison() {
new_ucmd!()
.args(&["1a", "<", "1", "+", "1"])
.succeeds()
.stdout_is("1\n");
}