From f482423b443bcc93e6aefc090afe415a310a8ccf Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Thu, 24 Mar 2011 17:34:52 -0400
Subject: [PATCH] Fix issue #40: bug in blank query detection.

Was ignoring non-ASCII characters. Thanks to github.com/supergivi for
reporting the bug.
---
 lib/geocoder.rb       | 2 +-
 test/geocoder_test.rb | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/geocoder.rb b/lib/geocoder.rb
index b9306ccd..4eee5874 100644
--- a/lib/geocoder.rb
+++ b/lib/geocoder.rb
@@ -131,7 +131,7 @@ module Geocoder
   # Is the given search query blank? (ie, should we not bother searching?)
   #
   def blank_query?(value)
-    !value.to_s.match(/[A-z0-9]/)
+    !!value.to_s.match(/^\s*$/)
   end
 end
 
diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb
index 9649a9a8..5443e64a 100644
--- a/test/geocoder_test.rb
+++ b/test/geocoder_test.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
 require 'test_helper'
 
 class GeocoderTest < Test::Unit::TestCase
@@ -213,8 +214,9 @@ class GeocoderTest < Test::Unit::TestCase
   def test_blank_query_detection
     assert Geocoder.send(:blank_query?, nil)
     assert Geocoder.send(:blank_query?, "")
-    assert Geocoder.send(:blank_query?, ", , (-)")
+    assert Geocoder.send(:blank_query?, "\t  ")
     assert !Geocoder.send(:blank_query?, "a")
+    assert !Geocoder.send(:blank_query?, "Москва") # no ASCII characters
   end
 
   def test_does_not_choke_on_nil_address
-- 
GitLab