Skip to content

Commit 9163d8a

Browse files
committed
merge prerelease branch
1 parent e3371f7 commit 9163d8a

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

ldcontext/context_easyjson.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ func parseKindOnlyEasyJSON(originalLexer *jlexer.Lexer) (Kind, bool, error) {
303303
in.WantColon()
304304
if key == ldattr.KindAttr {
305305
kind := in.String()
306+
if in.Error() == nil && kind == "" {
307+
return "", false, errContextKindEmpty
308+
}
306309
return Kind(kind), true, in.Error()
307310
}
308311
in.SkipRecursive()

ldcontext/context_unmarshaling.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ func parseKindOnly(originalReader *jreader.Reader) (Kind, bool, error) {
7272
r := *originalReader
7373
for obj := r.Object(); obj.Next(); {
7474
if string(obj.Name()) == ldattr.KindAttr {
75-
return Kind(r.String()), true, r.Error()
75+
kind := r.String()
76+
if r.Error() == nil && kind == "" {
77+
return "", false, errContextKindEmpty
78+
}
79+
return Kind(kind), true, r.Error()
7680
// We can immediately return here and not bother parsing the rest of the JSON object; we'll be
7781
// creating another Reader that'll start over with the same byte slice for the second pass.
7882
}

ldcontext/context_unmarshaling_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func contextUnmarshalingTests(t *testing.T, unmarshalFn func(*Context, []byte) e
234234

235235
`{"kind": "org"}`, // missing key
236236
`{"kind": "user", "key": ""}`, // empty key not allowed in new-style context
237+
`{"kind": "", "key": "x"}`, // empty kind not allowed in new-style context
237238
`{"kind": "ørg", "key": "x"}`, // illegal kind
238239

239240
// wrong type within _meta
@@ -346,6 +347,7 @@ func TestContextReadKindAndKeyOnly(t *testing.T) {
346347

347348
`{"kind": "org"}`, // missing key
348349
`{"kind": "user", "key": ""}`, // empty key not allowed in new-style context
350+
`{"kind": "", "key": "x"}`, // empty kind not allowed in new-style context
349351
`{"kind": "ørg", "key": "x"}`, // illegal kind
350352

351353
`{"kind": "multi"}`, // multi kind with no kinds

ldcontext/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
var (
88
errContextUninitialized = errors.New("tried to use uninitialized Context")
99
errContextKeyEmpty = errors.New("context key must not be empty")
10+
errContextKindEmpty = errors.New(`context kind cannot be empty`)
1011
errContextKindCannotBeKind = errors.New(`"kind" is not a valid context kind`)
1112
errContextKindMultiWithSimpleBuilder = errors.New(`context of kind "multi" must be built with NewMultiBuilder`)
1213
errContextKindMultiWithNoKinds = errors.New("multi-kind context must contain at least one kind")

0 commit comments

Comments
 (0)