fix: Allow spaces in query
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
d7d8ce6cd9
commit
d84f17e7ab
2 changed files with 11 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
@ -24,7 +25,7 @@ func New(siteName string) (*Nominatim, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Nominatim) Search(q string) (*SearchResults, 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)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -39,6 +39,15 @@ func TestSearch(t *testing.T) {
|
||||||
assert.Nil(firstResult.Address)
|
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) {
|
func TestLookup(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
c, err := New("my siteName")
|
c, err := New("my siteName")
|
||||||
|
|
Loading…
Reference in a new issue