webmock icon indicating copy to clipboard operation
webmock copied to clipboard

IndexError: string not matched is thrown on stub_request when uri contains parameters with same key name

Open zhivanova opened this issue 4 years ago • 2 comments

When stubbing a request that contains the same parameter with and without brackets, ex:

describe "test" do
      it "throws webmock error" do
        example = "https://google.com?foo=foo&foo%5Bbar%5D=fooBar"          # foo=foo&foo[bar]=fooBar

        stub_request(:get, example)
        .with(headers: {})
        .to_return(status: 200)

        call_test_method
      end
  end

the following error is thrown:

IndexError: string not matched
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/query_mapper.rb:166:in `[]='
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/query_mapper.rb:166:in `fill_accumulator_for_subscript'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/query_mapper.rb:88:in `block in collect_query_hash'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/query_mapper.rb:80:in `each'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/query_mapper.rb:80:in `inject'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/query_mapper.rb:80:in `collect_query_hash'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/query_mapper.rb:56:in `query_to_values'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/uri.rb:17:in `block in <class:URI>'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/util/uri.rb:33:in `normalize_uri'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/request_pattern.rb:118:in `initialize'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/request_pattern.rb:86:in `new'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/request_pattern.rb:86:in `create_uri_pattern'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/request_pattern.rb:19:in `initialize'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/request_stub.rb:7:in `new'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/request_stub.rb:7:in `initialize'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/api.rb:7:in `new'
    /home/user/.rvm/gems/ruby-2.7.2/gems/webmock-3.14.0/lib/webmock/api.rb:7:in `stub_request'

zhivanova avatar Oct 28 '21 09:10 zhivanova

WebMock by default doesn't support multiple params of the same type. Please check this comment: https://github.com/bblimke/webmock/issues/490#issuecomment-115179961

bblimke avatar Oct 28 '21 09:10 bblimke

WebMock by default doesn't support multiple params of the same type. Please check this comment: #490 (comment)

Thank you

zhivanova avatar Oct 28 '21 12:10 zhivanova