From f113ea6c739a9f34fc0c79b1857279b9c0803bf1 Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 25 Jan 2022 10:49:27 +0100 Subject: [PATCH] Fix parsing of variable names that are a suffix of '__curPos' Follow-up from #5969 Fix #5982 --- src/libexpr/parser.y | 2 +- tests/lang/eval-okay-regression-20220125.exp | 1 + tests/lang/eval-okay-regression-20220125.nix | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/lang/eval-okay-regression-20220125.exp create mode 100644 tests/lang/eval-okay-regression-20220125.nix diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 55f8abcb7..7a8e93c12 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -405,7 +405,7 @@ expr_select expr_simple : ID { std::string_view s = "__curPos"; - if (strncmp($1.p, s.data(), s.size()) == 0) + if ($1.l == s.size() && strncmp($1.p, s.data(), s.size()) == 0) $$ = new ExprPos(CUR_POS); else $$ = new ExprVar(CUR_POS, data->symbols.create($1)); diff --git a/tests/lang/eval-okay-regression-20220125.exp b/tests/lang/eval-okay-regression-20220125.exp new file mode 100644 index 000000000..00750edc0 --- /dev/null +++ b/tests/lang/eval-okay-regression-20220125.exp @@ -0,0 +1 @@ +3 diff --git a/tests/lang/eval-okay-regression-20220125.nix b/tests/lang/eval-okay-regression-20220125.nix new file mode 100644 index 000000000..485502373 --- /dev/null +++ b/tests/lang/eval-okay-regression-20220125.nix @@ -0,0 +1,2 @@ +((__curPosFoo: __curPosFoo) 1) + ((__curPosBar: __curPosBar) 2) +