Skip to content
Snippets Groups Projects
Commit ef4a8364 authored by Luke Wendling's avatar Luke Wendling
Browse files

use more forgiving 'unstructured' query format in Bing Locations API

parent 24184142
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,9 @@ module Geocoder::Lookup ...@@ -27,7 +27,9 @@ module Geocoder::Lookup
if !query.reverse_geocode? and r = query.options[:region] if !query.reverse_geocode? and r = query.options[:region]
url << "/#{r}" url << "/#{r}"
end end
url + "/" + URI.escape(query.sanitized_text.strip) + "?" # use the more forgiving 'unstructured' query format to allow special
# chars, newlines, brackets, typos.
url + "?q=" + URI.escape(query.sanitized_text.strip) + "&"
end end
def results(query) def results(query)
......
...@@ -12,7 +12,7 @@ class BingTest < GeocoderTestCase ...@@ -12,7 +12,7 @@ class BingTest < GeocoderTestCase
def test_query_for_reverse_geocode def test_query_for_reverse_geocode
lookup = Geocoder::Lookup::Bing.new lookup = Geocoder::Lookup::Bing.new
url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333])) url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333]))
assert_match(/Locations\/45.423733/, url) assert_match(/Locations\?q=45.423733/, url)
end end
def test_result_components def test_result_components
...@@ -33,7 +33,7 @@ class BingTest < GeocoderTestCase ...@@ -33,7 +33,7 @@ class BingTest < GeocoderTestCase
"manchester", "manchester",
:region => "uk" :region => "uk"
)) ))
assert_match(/Locations\/uk\/manchester/, url) assert_match(/Locations\/uk\?q=manchester/, url)
assert_no_match(/query/, url) assert_no_match(/query/, url)
end end
...@@ -42,7 +42,7 @@ class BingTest < GeocoderTestCase ...@@ -42,7 +42,7 @@ class BingTest < GeocoderTestCase
url = lookup.query_url(Geocoder::Query.new( url = lookup.query_url(Geocoder::Query.new(
"manchester" "manchester"
)) ))
assert_match(/Locations\/manchester/, url) assert_match(/Locations\?q=manchester/, url)
assert_no_match(/query/, url) assert_no_match(/query/, url)
end end
...@@ -52,7 +52,7 @@ class BingTest < GeocoderTestCase ...@@ -52,7 +52,7 @@ class BingTest < GeocoderTestCase
"manchester, lancashire", "manchester, lancashire",
:region => "uk" :region => "uk"
)) ))
assert_match(/Locations\/uk\/manchester,%20lancashire/, url) assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url)
assert_no_match(/query/, url) assert_no_match(/query/, url)
end end
...@@ -62,7 +62,7 @@ class BingTest < GeocoderTestCase ...@@ -62,7 +62,7 @@ class BingTest < GeocoderTestCase
" manchester, lancashire ", " manchester, lancashire ",
:region => "uk" :region => "uk"
)) ))
assert_match(/Locations\/uk\/manchester,%20lancashire/, url) assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url)
assert_no_match(/query/, url) assert_no_match(/query/, url)
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment