Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gqlgen truncates tag value with colon #2759

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions plugin/modelgen/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,19 @@ func removeDuplicateTags(t string) string {
continue
}

processed[kv[0]] = true
key := kv[0]
value := strings.Join(kv[1:], ":")
processed[key] = true
if len(returnTags) > 0 {
returnTags = " " + returnTags
}

isContained := containsInvalidSpace(kv[1])
isContained := containsInvalidSpace(value)
if isContained {
panic(fmt.Errorf("tag value should not contain any leading or trailing spaces: %s", kv[1]))
panic(fmt.Errorf("tag value should not contain any leading or trailing spaces: %s", value))
}

returnTags = kv[0] + ":" + kv[1] + returnTags
returnTags = key + ":" + value + returnTags
}

return returnTags
Expand Down
16 changes: 16 additions & 0 deletions plugin/modelgen/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,22 @@ func TestRemoveDuplicate(t *testing.T) {
want: "gorm:\"unique;not null\" json:\"name,name2\"",
wantPanic: false,
},
{
name: "Test gorm tag with colon",
args: args{
t: "gorm:\"type:varchar(63);unique_index\"",
},
want: "gorm:\"type:varchar(63);unique_index\"",
wantPanic: false,
},
{
name: "Test mix use of gorm and duplicate json tags with colon",
args: args{
t: "json:\"name0\" gorm:\"type:varchar(63);unique_index\" json:\"name,name2\"",
},
want: "gorm:\"type:varchar(63);unique_index\" json:\"name,name2\"",
wantPanic: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down