From ab5cf741850fdd05a68212842341096a5f562a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teemu=20P=C3=A4tsi?= Date: Sat, 24 May 2025 21:17:20 +0300 Subject: [PATCH] expr: Simplify parsing special cases for `$` in regex --- src/uu/expr/src/syntax_tree.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index 544b3b773..b0326f7b6 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -185,14 +185,8 @@ impl StringOp { | ('\\', false) => re_string.push(curr), _ => re_string.push_str(r"\^"), }, - '$' => { - if is_end_of_expression(&pattern_chars) { - re_string.push(curr); - } else if !curr_is_escaped { - re_string.push_str(r"\$"); - } else { - re_string.push(curr); - } + '$' if !curr_is_escaped && !is_end_of_expression(&pattern_chars) => { + re_string.push_str(r"\$"); } '\\' if !curr_is_escaped && pattern_chars.peek().is_none() => { return Err(ExprError::TrailingBackslash);