Fix multiword keyword quoting for search commands (#7170)

This commit is contained in:
Sam Coe 2023-03-16 09:19:26 +11:00 committed by GitHub
parent 999caaa09a
commit 7bd7153285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -147,7 +147,12 @@ func formatQualifiers(qs Qualifiers) []string {
func formatKeywords(ks []string) []string {
for i, k := range ks {
ks[i] = quote(k)
before, after, found := strings.Cut(k, ":")
if !found {
ks[i] = quote(k)
} else {
ks[i] = fmt.Sprintf("%s:%s", before, quote(after))
}
}
return ks
}

View file

@ -47,7 +47,14 @@ func TestQueryString(t *testing.T) {
query: Query{
Keywords: []string{"quote keywords"},
},
out: "\"quote keywords\"",
out: `"quote keywords"`,
},
{
name: "quotes keywords that are qualifiers",
query: Query{
Keywords: []string{"quote:keywords", "quote:multiword keywords"},
},
out: `quote:keywords quote:"multiword keywords"`,
},
{
name: "quotes qualifiers",
@ -56,7 +63,7 @@ func TestQueryString(t *testing.T) {
Topic: []string{"quote qualifier"},
},
},
out: "topic:\"quote qualifier\"",
out: `topic:"quote qualifier"`,
},
}
for _, tt := range tests {