From 75e762a017b6cba5d5f5f5e9a6c0627902f16e8b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 4 Mar 2011 11:45:21 -0500 Subject: [PATCH] Enhance blank search query checking. --- lib/geocoder.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/geocoder.rb b/lib/geocoder.rb index b7c8be64..8aec8c33 100644 --- a/lib/geocoder.rb +++ b/lib/geocoder.rb @@ -10,7 +10,7 @@ module Geocoder # Search for information about an address or a set of coordinates. # def search(*args) - return [] if args[0].nil? || args[0] == "" + return [] if blank_query?(args[0]) ip = (args.size == 1 and ip_address?(args.first)) lookup(ip).search(*args) end @@ -81,6 +81,13 @@ module Geocoder def ip_address?(value) value.match /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ end + + ## + # Is the given search query blank? (ie, should we not bother searching?) + # + def blank_query?(value) + !value.to_s.match(/[A-z0-9]/) + end end Geocoder::Railtie.insert -- GitLab