Skip to content

Commit

Permalink
Strip leading & trailing whitespace from query.
Browse files Browse the repository at this point in the history
Fixes #1662.
  • Loading branch information
alexreisner committed Dec 4, 2024
1 parent ec2f034 commit 95eeaba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/geocoder/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def sanitized_text
text.split(/\s*,\s*/).join(',')
end
else
text
text.strip
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/unit/query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 95eeaba

Please sign in to comment.