In implementing OAuth2 in my app, I need to handle URIs like:
http://localhost:3000/sessions/create/?code=lorem|ipsum
Not sure if it's a Rails 3 or Ruby 1.9.2 problem (maybe URI.parse), but in any event, WEBrick kicks Error bad URI
.
Anyone know of a workaround? Thanks.
I ran into the same requirement (and problem) recently. On Rails 3 and Ruby 1.9.2.
It is not a problem for our staging/production environment (nginx), but I was interested to find out what the problem was with WEBrick. Turns out the issue is down in the URI::Parser.split method, specifically how it's pattern matching is seeded with the URI::REGEXP::PATTERN constants.
You can "fix" this by adding the following to a config/environments/development.rb (assuming you'd only be using WEBrick in dev .. or you could put it in a config/initializers file)..
# this allows WEBrick to handle pipe symbols in query parameters
URI::DEFAULT_PARSER =
URI::Parser.new(:UNRESERVED => URI::REGEXP::PATTERN::UNRESERVED + '|')
NB: that's setting :UNRESERVED => "-_.!~*'()a-zA-Z\d|"
The initializer worked, but I ended up using URI.escape instead as it seemed cleaner and looks like it will handle more cases.
URI.join(origin_url, URI.escape(parsed_link)).to_s
Plus this code just didnt seem right
# I need this because URI.join in crawler.rb bombs with '|' symbols
old_verbose = $VERBOSE
$VERBOSE = nil
URI::DEFAULT_PARSER = URI::Parser.new(:UNRESERVED => URI::REGEXP::PATTERN::UNRESERVED + '|')
$VERBOSE = old_verbose
I ended up just swapping in Thin for WEBrick and haven't had issues.
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