I know this is a common error and i'm using a known solution but its still giving me the same error:
require 'open-uri'
url = "http://website.com/dirs/filex[a]"
safeurl = URI.parse(URI.encode(url))
...
Gives URI::InvalidURIError: bad URI(is not URI?):
I know its the [
and ]
characters causing this. But the URI.encode isn't doing anything
What am I doing wrong?
I think you meant to require uri, not open-uri. Also, according to the documentation you can specify a second parameter with extra characters to encode. Try passing []
there.
The code for this solution would be:
safeurl = URI.parse(URI.encode(url, "[]"))
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