diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 5509ac12ccb7853a52d7ff0ae66c6d35a656f9da..0149d144e8b1087d7b1eb6ecf0d801e49fd1b810 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -24,12 +24,17 @@ module Geocoder::Lookup def base_url(query) url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations" - if !query.reverse_geocode? and r = query.options[:region] - url << "/#{r}" + + if !query.reverse_geocode? + if r = query.options[:region] + url << "/#{r}" + end + # use the more forgiving 'unstructured' query format to allow special + # chars, newlines, brackets, typos. + url + "?q=" + URI.escape(query.sanitized_text.strip) + "&" + else + url + "/#{URI.escape(query.sanitized_text.strip)}?" end - # use the more forgiving 'unstructured' query format to allow special - # chars, newlines, brackets, typos. - url + "?q=" + URI.escape(query.sanitized_text.strip) + "&" end def results(query) diff --git a/test/unit/lookups/bing_test.rb b/test/unit/lookups/bing_test.rb index d7b31a1e7346fa408e91c699fd7e6aac7967cef8..9a63f90eb63c4f0c1bb8805061f98eecaf6a8eae 100644 --- a/test/unit/lookups/bing_test.rb +++ b/test/unit/lookups/bing_test.rb @@ -12,7 +12,7 @@ class BingTest < GeocoderTestCase def test_query_for_reverse_geocode lookup = Geocoder::Lookup::Bing.new url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333])) - assert_match(/Locations\?q=45.423733/, url) + assert_match(/Locations\/45.423733/, url) end def test_result_components