Fix escaped strings missing double quote

fixes #223
This commit is contained in:
tidwall 2021-06-30 13:18:28 -07:00
parent ca5c4b1e26
commit 2feb4037b4
2 changed files with 35 additions and 1 deletions

View File

@ -584,7 +584,7 @@ func tostr(json string) (raw string, str string) {
continue
}
}
break
return json[:i+1], unescape(json[1:i])
}
}
var ret string

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
"strings"
"testing"
"time"
@ -2086,3 +2087,36 @@ func TestBoolConvertQuery(t *testing.T) {
assert(t, trues == "[1,2,6,7,8]")
assert(t, falses == "[3,4,5,9,10,11]")
}
func TestModifierDoubleQuotes(t *testing.T) {
josn := `{
"data": [
{
"name": "Product P4",
"productId": "1bb3",
"vendorId": "10de"
},
{
"name": "Product P4",
"productId": "1cc3",
"vendorId": "20de"
},
{
"name": "Product P4",
"productId": "1dd3",
"vendorId": "30de"
}
]
}`
AddModifier("string", func(josn, arg string) string {
return strconv.Quote(josn)
})
res := Get(josn, "data.#.{name,value:{productId,vendorId}.@string.@ugly}")
assert(t, res.Raw == `[`+
`{"name":"Product P4","value":"{\"productId\":\"1bb3\",\"vendorId\":\"10de\"}"},`+
`{"name":"Product P4","value":"{\"productId\":\"1cc3\",\"vendorId\":\"20de\"}"},`+
`{"name":"Product P4","value":"{\"productId\":\"1dd3\",\"vendorId\":\"30de\"}"}`+
`]`)
}