Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
cb4a2864da
commit
c6163bb22f
@ -25,6 +25,19 @@ func init() {
|
|||||||
bracketSplitter = regexp.MustCompile("\\[|\\]")
|
bracketSplitter = regexp.MustCompile("\\[|\\]")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func btSplitter(str string) []string {
|
||||||
|
r := bracketSplitter.Split(str, -1)
|
||||||
|
for idx, s := range r {
|
||||||
|
if len(s) == 0 {
|
||||||
|
if len(r) > idx+1 {
|
||||||
|
copy(r[idx:], r[idx+1:])
|
||||||
|
r = r[:len(r)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
// Unmarshal will take a dest along with URL
|
// Unmarshal will take a dest along with URL
|
||||||
// query params and attempt to first turn the query params
|
// query params and attempt to first turn the query params
|
||||||
// into JSON and then unmarshal those into the dest variable
|
// into JSON and then unmarshal those into the dest variable
|
||||||
@ -86,7 +99,7 @@ func queryToMap(param string) (map[string]interface{}, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pieces := bracketSplitter.Split(rawKey, -1)
|
pieces := btSplitter(rawKey)
|
||||||
key := pieces[0]
|
key := pieces[0]
|
||||||
|
|
||||||
// If len==1 then rawKey has no [] chars and we can just
|
// If len==1 then rawKey has no [] chars and we can just
|
||||||
@ -136,7 +149,8 @@ func queryToMap(param string) (map[string]interface{}, error) {
|
|||||||
// pieces = [bar one two ]
|
// pieces = [bar one two ]
|
||||||
// and return "one[two]"
|
// and return "one[two]"
|
||||||
func buildNewKey(origKey string) string {
|
func buildNewKey(origKey string) string {
|
||||||
pieces := bracketSplitter.Split(origKey, -1)
|
pieces := btSplitter(origKey)
|
||||||
|
|
||||||
ret := origKey[len(pieces[0])+1:]
|
ret := origKey[len(pieces[0])+1:]
|
||||||
ret = ret[:len(pieces[1])] + ret[len(pieces[1])+1:]
|
ret = ret[:len(pieces[1])] + ret[len(pieces[1])+1:]
|
||||||
return ret
|
return ret
|
||||||
|
@ -5,6 +5,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestFuzz1(t *testing.T) {
|
||||||
|
b, err := ToJSON(`[^@hGl5=`)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_ = b
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleUnmarshal() {
|
func ExampleUnmarshal() {
|
||||||
type Ex struct {
|
type Ex struct {
|
||||||
A string `json:"a"`
|
A string `json:"a"`
|
||||||
|
Loading…
Reference in New Issue
Block a user