Skip to content

Commit a78023a

Browse files
committed
merge prerelease branch
1 parent 1cc8acd commit a78023a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ldcontext/context_easyjson.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func readOptStringEasyJSON(in *jlexer.Lexer) ldvalue.OptionalString {
358358
}
359359

360360
func readPrivateAttributesEasyJSON(in *jlexer.Lexer, c *Context, asLiterals bool) {
361+
c.privateAttrs = nil
361362
if in.IsNull() {
362363
in.SkipRecursive()
363364
return

ldcontext/context_unmarshaling_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,27 @@ func contextUnmarshalingTests(
287287
}
288288
})
289289
}
290+
291+
t.Run("unmarshaling twice", func(t *testing.T) {
292+
// This test verifies that if you take an uninitialized Context{}, and unmarshal it from JSON, and
293+
// then unmarshal the same instance again, you get the same result (i.e. fields are overwritten
294+
// rather than being appended).
295+
for _, p := range makeAllContextUnmarshalingParams() {
296+
t.Run(p.json, func(t *testing.T) {
297+
var c Context
298+
err := unmarshalSingleContextFn(&c, []byte(p.json))
299+
// Here we're using an if, rather than an assert, because we already asserted these conditions
300+
// in the "valid data" test. If something is really wrong such that it's returning an error or
301+
// the Equal test fails, we want that to show up more specifically in that test, rather than
302+
// producing confounding results in this one.
303+
if err == nil && c.Equal(p.context) {
304+
c1 := c
305+
require.NoError(t, unmarshalSingleContextFn(&c, []byte(p.json)))
306+
assert.Equal(t, c1, c)
307+
}
308+
})
309+
}
310+
})
290311
}
291312

292313
func jsonUnmarshalTestFn(c *Context, data []byte) error {

0 commit comments

Comments
 (0)