Skip to content

Commit

Permalink
Don't assume terminating single quote
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Sep 14, 2023
1 parent 33a1168 commit c9dceb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func newSelectorNode(selector string) *selectorNode {

func (n *selectorNode) filter(node ast.Node) (ast.Node, error) {
selector := n.selector
if len(selector) > 0 && selector[0] == '\'' {
if len(selector) > 0 && selector[0] == '\'' && selector[len(selector)-1] == '\'' {
selector = selector[1 : len(selector)-1]
}
switch node.Type() {
Expand All @@ -517,7 +517,9 @@ func (n *selectorNode) filter(node ast.Node) (ast.Node, error) {
return nil, errors.Wrapf(err, "failed to unquote")
}
case '\'':
key = key[1 : len(key)-1]
if key[len(key)-1] == '\'' {
key = key[1 : len(key)-1]
}
}
}
if key == selector {
Expand Down
7 changes: 6 additions & 1 deletion path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ store:
expected: float64(19.95),
},
{
name: `$.store.'bicycle*unicycle'.price`,
name: `$.store.'bicycle*unicycle.price`,
path: builder().Root().Child("store").Child(`bicycle*unicycle`).Child("price").Build(),
expected: float64(20.25),
},
//{
// name: `$.store.'bicycle*unicycle.price`,
// path: builder().Root().Child("store").Child(`bicycle*unicycle`).Child("price").Build(),
// expected: float64(20.25),
//},
}
t.Run("PathString", func(t *testing.T) {
for _, test := range tests {
Expand Down

0 comments on commit c9dceb2

Please sign in to comment.