Skip to content

Commit

Permalink
Escape field tags
Browse files Browse the repository at this point in the history
Fixes #266
  • Loading branch information
klauspost committed Oct 29, 2024
1 parent 1de3898 commit 8278b1b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions _generated/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type X struct {
Others [][32]int32 // should compile to len(x.Others)*32*msgp.Int32Size
Matrix [][]int32 // should not optimize
ManyFixed []Fixed
WeirdTag string `msg:"\x0b"`
}

// test fixed-size struct
Expand Down
2 changes: 1 addition & 1 deletion gen/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (d *decodeGen) structAsMap(s *Struct) {
d.p.print("\nswitch msgp.UnsafeString(field) {")
for i := range s.Fields {
d.ctx.PushString(s.Fields[i].FieldName)
d.p.printf("\ncase \"%s\":", s.Fields[i].FieldTag)
d.p.printf("\ncase %q:", s.Fields[i].FieldTag)
fieldElem := s.Fields[i].FieldElem
anField := s.Fields[i].HasTagPart("allownil") && fieldElem.AllowNil()
if anField {
Expand Down
2 changes: 1 addition & 1 deletion gen/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (u *unmarshalGen) mapstruct(s *Struct) {
if !u.p.ok() {
return
}
u.p.printf("\ncase \"%s\":", s.Fields[i].FieldTag)
u.p.printf("\ncase %q:", s.Fields[i].FieldTag)
u.ctx.PushString(s.Fields[i].FieldName)

fieldElem := s.Fields[i].FieldElem
Expand Down

0 comments on commit 8278b1b

Please sign in to comment.