perfectline / validates_url

URL Validation for Rails
MIT License
579 stars 114 forks source link

URI::InvalidURIError when passed characters outside ascii #127

Open madmax opened 2 years ago

madmax commented 2 years ago

When we pass some no ascii characters it will raise error with URI::InvalidURIError

example:

Model.new(url:"\u201C").valid?
ArgumentError: wrong number of arguments (given 3, expected 1..2)
from /Users/madmax/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/bundler/gems/rails-ba8d029e0c99/activemodel/lib/active_model/errors.rb:310:in `add'
Caused by URI::InvalidURIError: URI must be ascii only "\u201C"
from /Users/madmax/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:21:in `split'
espen commented 1 year ago

Can confirm. Does not handle Norwegian characters, for example https://example.org/path-with-ø/example

espen commented 1 year ago

This looks like a solution: uri = URI.parse(URI::Parser.new.escape(url)). See https://stackoverflow.com/questions/46849219/ruby-uriinvalidurierror-uri-must-be-ascii-only