Skip to content

Commit 557c6d8

Browse files
qiaodevcopybara-github
authored andcommitted
fix: missing zero value bug in setValueByPath. fixes #196
PiperOrigin-RevId: 742317778
1 parent 673a7f7 commit 557c6d8

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

common.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ func setValueByPath(data map[string]any, keys []string, value any) {
100100
}
101101
}
102102

103-
if !reflect.ValueOf(value).IsZero() {
104-
data[keys[len(keys)-1]] = value
105-
}
103+
data[keys[len(keys)-1]] = value
106104
}
107105

108106
// getValueByPath retrieves a value from a nested map or slice or struct based on a path of keys.

common_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ func TestSetValueByPath(t *testing.T) {
194194
value: "v",
195195
want: map[string]any{"a": map[string]any{"b": "v"}},
196196
},
197+
{
198+
name: "Empty_value",
199+
data: map[string]any{},
200+
keys: []string{"a", "b"},
201+
value: 0,
202+
want: map[string]any{"a": map[string]any{"b": 0}},
203+
},
197204
{
198205
name: "Nested",
199206
data: map[string]any{"a": map[string]any{}},

replay_api_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func (rac *replayAPIClient) assertRequest(sdkRequest *http.Request, replayReques
196196
}
197197
bodySegment = redactRequestBody(bodySegment)
198198
bodySegment = convertKeysToCamelCase(bodySegment, "").(map[string]any)
199+
omitEmptyValues(bodySegment)
199200

200201
headers := make(map[string]string)
201202
for k, v := range sdkRequest.Header {

0 commit comments

Comments
 (0)