Skip to content

Commit 95eeaba

Browse files
committed
Strip leading & trailing whitespace from query.
Fixes #1662.
1 parent ec2f034 commit 95eeaba

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/geocoder/query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def sanitized_text
2323
text.split(/\s*,\s*/).join(',')
2424
end
2525
else
26-
text
26+
text.strip
2727
end
2828
end
2929

test/unit/query_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def test_detect_non_ip_address
1616
assert !Geocoder::Query.new("::ffff:123.456.789").ip_address?
1717
end
1818

19+
def test_strip_trailing_whitespace_for_ip_address_query
20+
text = "77.251.213.1\n"
21+
query = Geocoder::Query.new(text)
22+
assert_equal text[0...-1], query.sanitized_text
23+
end
24+
1925
def test_blank_query_detection
2026
assert Geocoder::Query.new(nil).blank?
2127
assert Geocoder::Query.new("").blank?

0 commit comments

Comments
 (0)