fix: Allow spaces in query

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-09-29 21:49:23 +02:00
parent d7d8ce6cd9
commit d84f17e7ab
No known key found for this signature in database
GPG key ID: E59C7734F0E10EB5
2 changed files with 11 additions and 1 deletions

View file

@ -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 {

View file

@ -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")