Skip to content

Commit 7bd7153

Browse files
authored
Fix multiword keyword quoting for search commands (#7170)
1 parent 999caaa commit 7bd7153

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pkg/search/query.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ func formatQualifiers(qs Qualifiers) []string {
147147

148148
func formatKeywords(ks []string) []string {
149149
for i, k := range ks {
150-
ks[i] = quote(k)
150+
before, after, found := strings.Cut(k, ":")
151+
if !found {
152+
ks[i] = quote(k)
153+
} else {
154+
ks[i] = fmt.Sprintf("%s:%s", before, quote(after))
155+
}
151156
}
152157
return ks
153158
}

pkg/search/query_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ func TestQueryString(t *testing.T) {
4747
query: Query{
4848
Keywords: []string{"quote keywords"},
4949
},
50-
out: "\"quote keywords\"",
50+
out: `"quote keywords"`,
51+
},
52+
{
53+
name: "quotes keywords that are qualifiers",
54+
query: Query{
55+
Keywords: []string{"quote:keywords", "quote:multiword keywords"},
56+
},
57+
out: `quote:keywords quote:"multiword keywords"`,
5158
},
5259
{
5360
name: "quotes qualifiers",
@@ -56,7 +63,7 @@ func TestQueryString(t *testing.T) {
5663
Topic: []string{"quote qualifier"},
5764
},
5865
},
59-
out: "topic:\"quote qualifier\"",
66+
out: `topic:"quote qualifier"`,
6067
},
6168
}
6269
for _, tt := range tests {

0 commit comments

Comments
 (0)