1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

expr: coerce to string before comparing values

This commit is contained in:
Terts Diepraam 2023-12-18 22:11:04 +01:00
parent 92692c815d
commit 00b9cbe09e
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");
}