Skip to content

Commit

Permalink
fix: encode query URL when opening search
Browse files Browse the repository at this point in the history
  • Loading branch information
Crocmagnon committed Dec 3, 2024
1 parent ceb069d commit cac1a79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/text/unicode/norm"
"io"
"net/http"
"net/url"
"os"
"strings"
)
Expand Down Expand Up @@ -69,11 +70,14 @@ func paperlessToAlfred(
) []alfred.Item {
var items []alfred.Item

encodedQuery := url.Values{"query": []string{query}}.Encode()

if len(results) == 0 {
items = append(items, alfred.Item{
Title: "No result found",
Arg: fmt.Sprintf("%s/documents?query=%s", baseURL, query),
Subtitle: "Open search in Paperless",
UID: "paperless:open-search",
Title: "Open search in Paperless",
Arg: fmt.Sprintf("%s/documents?%s", baseURL, encodedQuery),
Subtitle: fmt.Sprintf("Search for %q in Paperless", query),
})

return items
Expand All @@ -91,8 +95,8 @@ func paperlessToAlfred(
},
Mods: map[string]alfred.Mod{
"cmd": {
Arg: fmt.Sprintf("%s/documents?query=%s", baseURL, query),
Subtitle: "Open search in Paperless",
Arg: fmt.Sprintf("%s/documents?%s", baseURL, encodedQuery),
Subtitle: fmt.Sprintf("Open search for %q in Paperless", query),
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Test_run(t *testing.T) {
Arg: "http://localhost:1234/documents/12/details",
Icon: &alfred.Icon{Type: "filetype", Path: "com.adobe.pdf"},
Mods: map[string]alfred.Mod{
"cmd": {Arg: "http://localhost:1234/documents?query=simple", Subtitle: "Open search in Paperless"},
"cmd": {Arg: "http://localhost:1234/documents?query=simple", Subtitle: `Open search for "simple" in Paperless`},
},
},
},
Expand Down Expand Up @@ -135,7 +135,7 @@ func Test_run(t *testing.T) {
Arg: "http://localhost:1234/documents/11/details",
Icon: &alfred.Icon{Type: "filetype", Path: "com.adobe.pdf"},
Mods: map[string]alfred.Mod{
"cmd": {Arg: "http://localhost:1234/documents?query=complex querÿ", Subtitle: "Open search in Paperless"},
"cmd": {Arg: "http://localhost:1234/documents?query=complex+quer%C3%BF", Subtitle: `Open search for "complex querÿ" in Paperless`},
},
},
{
Expand All @@ -145,7 +145,7 @@ func Test_run(t *testing.T) {
Arg: "http://localhost:1234/documents/12/details",
Icon: &alfred.Icon{Type: "filetype", Path: "com.adobe.pdf"},
Mods: map[string]alfred.Mod{
"cmd": {Arg: "http://localhost:1234/documents?query=complex querÿ", Subtitle: "Open search in Paperless"},
"cmd": {Arg: "http://localhost:1234/documents?query=complex+quer%C3%BF", Subtitle: `Open search for "complex querÿ" in Paperless`},
},
},
},
Expand Down

0 comments on commit cac1a79

Please sign in to comment.