Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping of URI delimiter characters #240

Closed
kjbkjb opened this issue Jan 12, 2013 · 11 comments
Closed

Escaping of URI delimiter characters #240

kjbkjb opened this issue Jan 12, 2013 · 11 comments

Comments

@kjbkjb
Copy link

kjbkjb commented Jan 12, 2013

After upgrading from v1.8.7 to v1.9.0, our tests that use VCR started failing with the following error:

An HTTP request has been made that VCR does not know how to handle:
GET http://localhost:3001/xxxxxxx.json?conditions%5Bxxx_id%5D=1

%5B and %5D are [ and ] respectively. They are general delimiter characters according to section 2.2 of this spec: http://www.ietf.org/rfc/rfc3986.txt

I've tried different versions of rails and vcr to verify that the change happened within WebMock.

@kjbkjb
Copy link
Author

kjbkjb commented Jan 12, 2013

It appears as though the encoding is happening here:
https://github.com/bblimke/webmock/blob/master/lib/webmock/util/uri.rb#L20

Is it appropriate to modify the actual url that is forwarded in the http stack or should the original url be used to make the http call?

@kjbkjb
Copy link
Author

kjbkjb commented Jan 12, 2013

I see there is a small flame on Addressable about [] subquery blah blah.
sporkmonger/addressable#77

It would be nice if there was a feature that allowed for pass-through non-normalized uri's.

@bblimke
Copy link
Owner

bblimke commented Jan 12, 2013

Hi @kjbkjb

Thanks for reporting that.

Changes in addressable >= 2.3 are indeed breaking webmock, that's why I just took QueryMapper from addressable < 2.3 https://github.com/bblimke/webmock/blob/master/lib/webmock/util/query_mapper.rb

Are you able to provide a test or sample code using webmock that demonstrates this bug?

@kjbkjb
Copy link
Author

kjbkjb commented Jan 12, 2013

Sure, I'll get something to you in the next day or so.

@sunnyrjuneja
Copy link

@bblimke What's the status on this? I'm having a problem where I'm using faraday which encodes [ and ] into %5B and %5D but webmock leaves it as [ and ].

Is there anything blocking #243 ? I would love to help close this issue and move the PR forward.

@bblimke
Copy link
Owner

bblimke commented Apr 5, 2014

@whatasunnyday there was no progress unfortunately. Are you experiencing these problems when using VCR with WebMock?

@sunnyrjuneja
Copy link

I am not. I am using Faraday and webmock and found this thread while trying to google my issue.

Ruby Version:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]

Gemfile:

source 'https://rubygems.org'

gem 'faraday'
gem 'webmock'

reproduce.rb

require 'faraday'
require 'webmock'
include WebMock::API

URL = 'http://mock.com'
nested_hash = { 'example' => {'a' => 'z' } }

stub_request(:get, URL).with(query: nested_hash)

conn = Faraday.new(:url => URL) do |faraday|
  faraday.response :logger
  faraday.adapter  Faraday.default_adapter
end

conn.post do |req|
  req.params = nested_hash
end
# bundle exec ruby reproduce.rb
I, [2014-04-05T13:34:06.566084 #18366]  INFO -- : post http://mock.com/?example%5Ba%5D=z
D, [2014-04-05T13:34:06.566186 #18366] DEBUG -- request: User-Agent: "Faraday v0.9.0"
/Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/webmock-1.17.4/lib/webmock/http_lib_adapters/net_http.rb:114:in `request': Real HTTP connections are disabled. Unregistered request: POST http://mock.com/?example%5Ba%5D=z with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.0'} (WebMock::NetConnectNotAllowedError)

You can stub this request with the following snippet:

stub_request(:post, "http://mock.com/?example%5Ba%5D=z").
  with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.0'}).
  to_return(:status => 200, :body => "", :headers => {})

registered request stubs:

stub_request(:get, "http://mock.com/?example[a]=z")

============================================================
        from /Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
        from /Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
        from /Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/faraday-0.9.0/lib/faraday/response.rb:8:in `call'
        from /Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/faraday-0.9.0/lib/faraday/response/logger.rb:20:in `call'
        from /Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
        from /Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
        from /Users/sunnyjuneja/.rvm/gems/ruby-2.1.0/gems/faraday-0.9.0/lib/faraday/connection.rb:177:in `post'
        from reproduce.rb:15:in `<main>'

Any ideas on how to resolve this?

@bblimke
Copy link
Owner

bblimke commented Apr 9, 2014

Your stub is for a GET request and you make a POST request. Make sure they are the same and it should match fine.
It has nothing to do with escaping brackets.

@sunnyrjuneja
Copy link

I think my project actually had this issue but I'm failing to reproduce this correctly. At the time, I had not confused :get and :post. Since my project is OSS, I might be able to find a commit where it exists. I ended up testing it a different way.

I'm still interested in helping resolve this bug even if I didn't have it.

@bblimke
Copy link
Owner

bblimke commented Apr 10, 2014

Please let me know if you find a sample code to reproduce it.

@davidbegin
Copy link
Collaborator

closing this, as it looks like it might be resolved. If you have more information please reopen. Thanks for submitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants