Skip to content

Commit deb0af2

Browse files
committed
Allow true/false/null to be name selectors
1 parent 30532b8 commit deb0af2

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ All notable changes to this project will be documented in this file. It uses the
99

1010
## [v0.10.1] — Unreleased
1111

12+
### 🐞 Bug Fixes
13+
14+
* Allow `true`, `false`, and `null` to be used as selectors, e.g., `$.true`.
1215

1316
### 📔 Notes
1417

parser/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (p *parser) parseQuery(root bool) (*spec.PathQuery, error) {
114114
// parsed Selector.
115115
func parseNameOrWildcard(lex *lexer) (spec.Selector, error) {
116116
switch tok := lex.scan(); tok.tok {
117-
case identifier:
117+
case identifier, boolTrue, boolFalse, jsonNull:
118118
return spec.Name(tok.val), nil
119119
case '*':
120120
return spec.Wildcard(), nil

parser/parse_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ func TestParseSimple(t *testing.T) {
149149
spec.Descendant(spec.Name("xyz")),
150150
),
151151
},
152+
{
153+
test: "true_for_name",
154+
path: `$.true`,
155+
exp: spec.Query(
156+
true,
157+
spec.Child(spec.Name("true")),
158+
),
159+
},
160+
{
161+
test: "false_for_name",
162+
path: `$.false`,
163+
exp: spec.Query(
164+
true,
165+
spec.Child(spec.Name("false")),
166+
),
167+
},
168+
{
169+
test: "null_for_name",
170+
path: `$.null`,
171+
exp: spec.Query(
172+
true,
173+
spec.Child(spec.Name("null")),
174+
),
175+
},
152176
{
153177
test: "empty_string",
154178
path: "",

0 commit comments

Comments
 (0)