From 25cddad47b4a5cdb0578e100f92d7928975e5f35 Mon Sep 17 00:00:00 2001 From: kigland Date: Mon, 1 Jun 2026 13:36:50 +0800 Subject: [PATCH] fix extended parser boolean prefix fields --- CHANGELOG.md | 3 +++ jsonpath_ng/ext/parser.py | 2 +- tests/test_jsonpath_rw_ext.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55ad1a7..c033527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fix extended parser handling of field names that start with `true` or `false`. + ## [1.8.0] - 2026-02-24 ### Added diff --git a/jsonpath_ng/ext/parser.py b/jsonpath_ng/ext/parser.py index 8d75a42..7e3d372 100644 --- a/jsonpath_ng/ext/parser.py +++ b/jsonpath_ng/ext/parser.py @@ -31,7 +31,7 @@ class ExtendedJsonPathLexer(lexer.JsonPathLexer): t_FILTER_OP = r'=~|==?|<=|>=|!=|<|>' def t_BOOL(self, t): - r'true|false' + r'true(?![a-zA-Z0-9_@\-])|false(?![a-zA-Z0-9_@\-])' t.value = True if t.value == 'true' else False return t diff --git a/tests/test_jsonpath_rw_ext.py b/tests/test_jsonpath_rw_ext.py index ca1c3e9..a8649c3 100644 --- a/tests/test_jsonpath_rw_ext.py +++ b/tests/test_jsonpath_rw_ext.py @@ -484,6 +484,18 @@ ["green"], id="boolean-filter-string-true-string-literal", ), + pytest.param( + "false_positives", + {"problems_detected": 4, "false_positives": 2}, + [2], + id="field-starting-with-false", + ), + pytest.param( + "trueName", + {"trueName": "value"}, + ["value"], + id="field-starting-with-true", + ), pytest.param( "foo[?flag = true].color", {