From 95eeaba15714ff57052abc89f2c54a3415fa6139 Mon Sep 17 00:00:00 2001 From: Alex Reisner Date: Wed, 4 Dec 2024 11:04:44 -0800 Subject: [PATCH] Strip leading & trailing whitespace from query. Fixes #1662. --- lib/geocoder/query.rb | 2 +- test/unit/query_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/query.rb b/lib/geocoder/query.rb index 223cb3167..c8d2a67a0 100644 --- a/lib/geocoder/query.rb +++ b/lib/geocoder/query.rb @@ -23,7 +23,7 @@ def sanitized_text text.split(/\s*,\s*/).join(',') end else - text + text.strip end end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 5675461b4..ac3a313a1 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -16,6 +16,12 @@ def test_detect_non_ip_address assert !Geocoder::Query.new("::ffff:123.456.789").ip_address? end + def test_strip_trailing_whitespace_for_ip_address_query + text = "77.251.213.1\n" + query = Geocoder::Query.new(text) + assert_equal text[0...-1], query.sanitized_text + end + def test_blank_query_detection assert Geocoder::Query.new(nil).blank? assert Geocoder::Query.new("").blank?