Skip to content

Commit e6aaa0b

Browse files
committed
chore: rebuild project due to codegen change
1 parent a58f282 commit e6aaa0b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Diff for: internal/apijson/encoder.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"reflect"
88
"sort"
99
"strconv"
10+
"strings"
1011
"sync"
1112
"time"
1213

@@ -342,16 +343,18 @@ func (e *encoder) encodeMapEntries(json []byte, v reflect.Value) ([]byte, error)
342343

343344
iter := v.MapRange()
344345
for iter.Next() {
345-
var encodedKey []byte
346+
var encodedKeyString string
346347
if iter.Key().Type().Kind() == reflect.String {
347-
encodedKey = []byte(iter.Key().String())
348+
encodedKeyString = iter.Key().String()
348349
} else {
349350
var err error
350-
encodedKey, err = keyEncoder(iter.Key())
351+
encodedKeyBytes, err := keyEncoder(iter.Key())
351352
if err != nil {
352353
return nil, err
353354
}
355+
encodedKeyString = string(encodedKeyBytes)
354356
}
357+
encodedKey := []byte(sjsonReplacer.Replace(encodedKeyString))
355358
pairs = append(pairs, mapPair{key: encodedKey, value: iter.Value()})
356359
}
357360

@@ -389,3 +392,7 @@ func (e *encoder) newMapEncoder(t reflect.Type) encoderFunc {
389392
return json, nil
390393
}
391394
}
395+
396+
// If we want to set a literal key value into JSON using sjson, we need to make sure it doesn't have
397+
// special characters that sjson interprets as a path.
398+
var sjsonReplacer *strings.Replacer = strings.NewReplacer(".", "\\.", ":", "\\:", "*", "\\*")

Diff for: internal/apijson/json_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ var tests = map[string]struct {
361361
"date_time_missing_timezone_colon_coerce": {`"2007-03-01T13:03:05-1200"`, time.Date(2007, time.March, 1, 13, 3, 5, 0, time.FixedZone("", -12*60*60))},
362362
"date_time_nano_missing_t_coerce": {`"2007-03-01 13:03:05.123456789Z"`, time.Date(2007, time.March, 1, 13, 3, 5, 123456789, time.UTC)},
363363

364-
"map_string": {`{"foo":"bar"}`, map[string]string{"foo": "bar"}},
365-
"map_interface": {`{"a":1,"b":"str","c":false}`, map[string]interface{}{"a": float64(1), "b": "str", "c": false}},
364+
"map_string": {`{"foo":"bar"}`, map[string]string{"foo": "bar"}},
365+
"map_string_with_sjson_path_chars": {`{":a.b.c*:d*-1e.f":"bar"}`, map[string]string{":a.b.c*:d*-1e.f": "bar"}},
366+
"map_interface": {`{"a":1,"b":"str","c":false}`, map[string]interface{}{"a": float64(1), "b": "str", "c": false}},
366367

367368
"primitive_struct": {
368369
`{"a":false,"b":237628372683,"c":654,"d":9999.43,"e":43.76,"f":[1,2,3,4]}`,

0 commit comments

Comments
 (0)