From d3a134957c5d50327f8aaa4b101e164da140de9c Mon Sep 17 00:00:00 2001 From: tidwall Date: Thu, 25 Nov 2021 13:57:06 -0700 Subject: [PATCH] Fix modifier bug in multipath selector Closes #253 --- gjson.go | 9 +++++---- gjson_test.go | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gjson.go b/gjson.go index e74551f..8783aac 100644 --- a/gjson.go +++ b/gjson.go @@ -1728,7 +1728,7 @@ type subSelector struct { // first character in path is either '[' or '{', and has already been checked // prior to calling this function. func parseSubSelectors(path string) (sels []subSelector, out string, ok bool) { - modifer := 0 + modifier := 0 depth := 1 colon := 0 start := 1 @@ -1743,6 +1743,7 @@ func parseSubSelectors(path string) (sels []subSelector, out string, ok bool) { } sels = append(sels, sel) colon = 0 + modifier = 0 start = i + 1 } for ; i < len(path); i++ { @@ -1750,11 +1751,11 @@ func parseSubSelectors(path string) (sels []subSelector, out string, ok bool) { case '\\': i++ case '@': - if modifer == 0 && i > 0 && (path[i-1] == '.' || path[i-1] == '|') { - modifer = i + if modifier == 0 && i > 0 && (path[i-1] == '.' || path[i-1] == '|') { + modifier = i } case ':': - if modifer == 0 && colon == 0 && depth == 1 { + if modifier == 0 && colon == 0 && depth == 1 { colon = i } case ',': diff --git a/gjson_test.go b/gjson_test.go index 50760c2..bb084ea 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -1892,6 +1892,9 @@ func TestModifiersInMultipaths(t *testing.T) { exp = `{"first":"DALE"}` assert(t, res.Raw == exp) + res = Get(readmeJSON, `{"children":children|@case:upper,"name":name.first,"age":age}`) + exp = `{"children":["SARA","ALEX","JACK"],"name":"Tom","age":37}` + assert(t, res.Raw == exp) } func TestIssue141(t *testing.T) {