Skip to content

Commit

Permalink
fix: when parsing map length entries look for the key exactly equalli…
Browse files Browse the repository at this point in the history
…ng % rather than being prefixed with it, to allow for map keys names to start with %
  • Loading branch information
Steven Bogacz committed Aug 26, 2024
1 parent 651ff33 commit 5d41d84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion helper/schema/field_reader_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func (r *DiffFieldReader) readMap(
if !strings.HasPrefix(k, prefix) {
continue
}
if strings.HasPrefix(k, prefix+"%") {

key := k[len(prefix):]
if key == "%" {
// Ignore the count field
continue
}
Expand Down
9 changes: 7 additions & 2 deletions helper/schema/field_reader_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func TestDiffFieldReader_MapHandling(t *testing.T) {
Old: "",
New: "qux",
},
"tags.%baz": {
Old: "",
New: "%qux",
},
},
},
Source: &MapFieldReader{
Expand All @@ -148,8 +152,9 @@ func TestDiffFieldReader_MapHandling(t *testing.T) {
}

expected := map[string]interface{}{
"foo": "bar",
"baz": "qux",
"foo": "bar",
"baz": "qux",
"%baz": "%qux",
}

if !reflect.DeepEqual(expected, result.Value) {
Expand Down

0 comments on commit 5d41d84

Please sign in to comment.