On Jul 2, 10:04 pm, Ken Mayer <
li...@bitwrangler.com> wrote:
> This is not really fakeweb's fault, but perhaps there's another way to
> handle Basic Auth... If the username is an e-mail address (which is
> used more and more frequently, then the Standard Library URI parse
> croaks on the URI passed in.
>
> Here's how I reproduce this:
>
> $ gem list -l fakeweb
> fakeweb (1.2.4)
> r$ irb -rubygems -r fakeweb
> irb(main):001:0> FakeWeb.register_uri(:get, "http://
> some...@example.org:test@localhost:3000/foobar.html", :body => "")
> URI::InvalidURIError: the scheme http does not accept registry part:
> some...@example.org:test@localhost:3000 (or bad hostname?)
Hey Ken, thanks for posting. I think what you were trying to do is not
quite valid, but I wrote a test for the actual valid approach and it
doesn't work either :) oops. So I just fixed that:
http://github.com/chrisk/fakeweb/commit/1ad638500be9ddd570c6a888e5b344a2f8e82216
Here's what you should do once that's released (in 1.2.5):
# percent-encode unsafe characters in the userinfo part, per RFC 3986
FakeWeb.register_uri(:get, "
http://someone
%40example.org:test@localhost:3000/foobar.html", :body => "")
http = Net::HTTP.new("localhost", 3000)
request = Net::HTTP::Get.new("/foobar.html")
request.basic_auth("
som...@example.org", "test") # but no need to
escape here, since it's not a URI
http.request(request)
That should do the trick. I'll try to release 1.2.5 soon -- I need to
refactor the ugly implementation in that commit a bit, and write some
more tests.
Thanks again,
Chris