From d84f17e7ab845de512e5cf3df5321ab8769d1265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20H=C3=A5rek=20Andreassen?= Date: Sun, 29 Sep 2024 21:49:23 +0200 Subject: [PATCH] fix: Allow spaces in query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim HĂ„rek Andreassen --- internal/nominatim/nominatim.go | 3 ++- internal/nominatim/nominatim_test.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/nominatim/nominatim.go b/internal/nominatim/nominatim.go index a5fc7e7..9c0c746 100644 --- a/internal/nominatim/nominatim.go +++ b/internal/nominatim/nominatim.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/http" + "net/url" "reflect" "strconv" ) @@ -24,7 +25,7 @@ func New(siteName string) (*Nominatim, error) { } func (n *Nominatim) Search(q string) (*SearchResults, error) { - url := fmt.Sprintf("https://nominatim.openstreetmap.org/search?q=%s&format=jsonv2", q) + url := fmt.Sprintf("https://nominatim.openstreetmap.org/search?q=%s&format=jsonv2", url.QueryEscape(q)) req, err := http.NewRequest("GET", url, nil) if err != nil { diff --git a/internal/nominatim/nominatim_test.go b/internal/nominatim/nominatim_test.go index c7e69d6..099026c 100644 --- a/internal/nominatim/nominatim_test.go +++ b/internal/nominatim/nominatim_test.go @@ -39,6 +39,15 @@ func TestSearch(t *testing.T) { assert.Nil(firstResult.Address) } +func TestSearchWithSpaceInQuery(t *testing.T) { + assert := assert.New(t) + c, err := New("my siteName") + assert.NoError(err) + + _, err = c.Search("drotningsvik senter") + assert.NoError(err) +} + func TestLookup(t *testing.T) { assert := assert.New(t) c, err := New("my siteName")