Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search by IP should sanitize the input #1662

Open
opensourceame opened this issue Sep 3, 2024 · 1 comment
Open

Search by IP should sanitize the input #1662

opensourceame opened this issue Sep 3, 2024 · 1 comment

Comments

@opensourceame
Copy link
Contributor

Expected behavior

When searching by IP, correct results for an IP address should be returned.

Actual behavior

Incorrect results are returned if there is, for example, a carriage return character at the end of the string. Thus the search function should sanitize the input and strip invalid characters from the string.

Steps to reproduce

pry(main)> ip = '77.251.213.1'
pry(main)> search  = Geocoder.search(ip)
[
    [0] #<Geocoder::Result::IpinfoIo:0x0000ffffa9da69f8 @data={"ip"=>"77.251.213.1", "hostname"=>"dhcp-077-251-213-001.chello.nl", "city"=>"Amsterdam", "region"=>"North Holland", "country"=>"NL", "loc"=>"52.3740,4.8897", "org"=>"AS33915 Vodafone Libertel B.V.", "postal"=>"1012", "timezone"=>"Europe/Amsterdam", "readme"=>"https://ipinfo.io/missingauth"}, @cache_hit=nil>
]

pry(main)> ip = "77.251.213.1\n"
Geocoding API's response was not valid JSON
[]

I think the solution is to fix Geocoder::Query.sanitized_text() - should I make a PR for this?

Environment info

  • Geocoder version: 1.8.2
  • Rails version: 7.1
  • Database (if applicable):
  • Lookup (if applicable):
@opensourceame opensourceame changed the title Search by should sanitize the input Search by IP should sanitize the input Sep 3, 2024
@alexreisner
Copy link
Owner

Yep! I think it's reasonable to add .strip to the end of line 23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants