From 3a390fba7737e878becb0c7ba77c6f01d13272f5 Mon Sep 17 00:00:00 2001
From: johngallagher <john@synapticmishap.co.uk>
Date: Fri, 9 Aug 2013 15:17:14 +0100
Subject: [PATCH] stripping leadding and trailing whitespace from location
 input

---
 lib/geocoder/lookups/bing.rb |  2 +-
 test/services_test.rb        | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb
index 032942ef..ce78da80 100644
--- a/lib/geocoder/lookups/bing.rb
+++ b/lib/geocoder/lookups/bing.rb
@@ -29,7 +29,7 @@ module Geocoder::Lookup
     end
 
     def sanitized_text(query)
-      URI.escape(query.sanitized_text) if !query.reverse_geocode?
+      URI.escape(query.sanitized_text.strip) if !query.reverse_geocode?
     end
 
     def results(query)
diff --git a/test/services_test.rb b/test/services_test.rb
index ba37b5f2..70e8109d 100644
--- a/test/services_test.rb
+++ b/test/services_test.rb
@@ -274,6 +274,16 @@ class ServicesTest < Test::Unit::TestCase
     assert_no_match /query/, url
   end
 
+  def test_bing_query_url_contains_address_with_trailing_and_leading_spaces
+    lookup = Geocoder::Lookup::Bing.new
+    url = lookup.query_url(Geocoder::Query.new(
+      " manchester, lancashire ",
+      :region => "uk"
+    ))
+    assert_match /Locations\/uk\/manchester,%20lancashire/, url
+    assert_no_match /query/, url
+  end
+
   # --- Nominatim ---
 
   def test_nominatim_result_components
-- 
GitLab