Skip to content

Commit 3454e6c

Browse files
authored
chore: fix '-' serialization tag handling (#137)
The `-` exclusion is only when `"-"` is as-is, not when it has trailers (e.g, `"-,"`)
1 parent a030b77 commit 3454e6c

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

_tools/libddwaf-updater/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module github.com/DataDog/go-libddwaf/libddwaf-updater
1+
module github.com/DataDog/go-libddwaf/_tools/libddwaf-updater
22

3-
go 1.20
3+
go 1.23.0
44

55
require (
66
github.com/bitfield/script v0.22.0

_tools/ruleset-updater/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module github.com/DataDog/go-libddwaf/_tools/ruleset-updater
22

33
go 1.23.0
44

5-
toolchain go1.24.3
6-
75
require (
86
github.com/google/go-github/v72 v72.0.0
97
github.com/iancoleman/orderedmap v0.3.0

encoder.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,18 @@ func getFieldNameFromType(field reflect.StructField) (string, bool) {
316316
if !ok {
317317
continue
318318
}
319+
if tag == "-" {
320+
// Explicitly ignored, note that only "-" causes the field to be ignored,
321+
// any qualifier ("-,omitempty" or event "-,") will cause the field to be
322+
// actually named "-" instead of being ignored.
323+
return "", false
324+
}
319325
contentTypeTag = true
320326
tag, _, _ = strings.Cut(tag, ",")
321327
switch tag {
322328
case "":
323329
// Nothing to do
324330
continue
325-
case "-":
326-
// Explicitly ignored
327-
return "", false
328331
default:
329332
return tag, true
330333
}

encoder_decoder_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,9 @@ func TestEncoderLimits(t *testing.T) {
618618
Ignored string `json:"-"`
619619
Transparent string `json:",omitempty"`
620620
Renamed string `json:"field"`
621-
}{Ignored: "1", Transparent: "2", Renamed: "3"},
622-
Output: map[string]any{"Transparent": "2", "field": "3"},
621+
LiteralDash string `json:"-,"`
622+
}{Ignored: "1", Transparent: "2", Renamed: "3", LiteralDash: "4"},
623+
Output: map[string]any{"Transparent": "2", "field": "3", "-": "4"},
623624
},
624625
{
625626
Name: "xml-tagged",

0 commit comments

Comments
 (0)