Skip to content

Commit be9b9ab

Browse files
committed
fix(os/gstructs): strip tag options in TagPriorityName to avoid field name pollution
TagPriorityName() returned raw tag values including options like ",omitempty", causing RuleFuncInput.Field to be "user_name,omitempty" instead of "user_name". Now splits on comma and takes only the name part, consistent with structcache.genPriorityTagAndFieldName(). closes gogf#4665
1 parent 6a3ea89 commit be9b9ab

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

os/gstructs/gstructs_field_tag.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ func (f *Field) TagPriorityName() string {
101101
name := f.Name()
102102
for _, tagName := range gtag.StructTagPriority {
103103
if tagValue := f.Tag(tagName); tagValue != "" {
104-
name = tagValue
105-
break
104+
// Strip tag options after comma, e.g., json:"name,omitempty" -> "name".
105+
if index := strings.Index(tagValue, ","); index != -1 {
106+
tagValue = tagValue[:index]
107+
}
108+
if tagValue != "" {
109+
name = tagValue
110+
break
111+
}
106112
}
107113
}
108114
return name

0 commit comments

Comments
 (0)