I am trying to implement an OAuth provider in Rails 3. When I try to authorize a client app I get this error. I am using the RESTful auth plugin and pelles OAuth-plugin. When I was testing via the Rails console and getting this error I thought that I simply needed to encode the URLs but I get the same error when testing in browser so I am not sure what is wrong.
URI.parse is right: that URI is illegal. Just because it accidentally happens to work in your browser doesn't make it legal. You cannot parse that URI, because it isn't a URI. Show activity on this post.
There are several characters that you should encode with URI::encode (). For instance, #, , or & are not valid in a query.
Check your url is not nil, and it's a valid one. Do URI.encode (url) before URI.parse (to avoid special characters) Do strip to the string you pass to URI.parse (to avoid leading and trailing whitespaces).
Addressable::URI is a better, more rfc-compliant replacement for URI: gem install addressable first. Show activity on this post. Show activity on this post.
I got into trouble with URI.split
(returning this error), I don't know if this helps you, but I will post here some warnings for also someone else having this error:
URI.encode(url)
before URI.parse
(to avoid special characters)strip
to the string you pass to URI.parse
(to avoid leading and trailing whitespaces).All in one:
uri = URI.parse(URI.encode(url.strip))
Related resource: http://www.practicalguile.com/2007/09/15/raising-uriinvalidurierror-from-a-perfectly-valid-uri/
You can also use this alternative URI gem: https://github.com/sporkmonger/addressable
There is no such problems with it.
Very native, just add namespace in your code after installing the gem
Addressable::URI
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With