Open ruanwz opened 9 years ago
Thanks @ruanwz. Could you send a sample contract or create a test scenario? I think you found a bug, but maybe not quite the one you thought.
That line obviously can return nil, but I don't think it should so setting a default value might not be the best fix. I suspect the actual problem is related to optional slashes in the path. The URI template is probably built with a slash, but then getting called with a URI that doesn't contain one:
t = Addressable::Template.new('http://abc.com/{?othervars*}')
# works with a slash
uri = Addressable::URI.heuristic_parse('http://abc.com/?a=3&d=4')
t.extract uri
# => {"othervars"=>{"a"=>"3", "d"=>"4"}}
# fails without a slash
uri = Addressable::URI.heuristic_parse('http://abc.com?a=3&d=4')
t.extract uri
# => nil
Many APIs don't care if the final slash is present or not, so Pacto should probably treat '/?a=3&d=4' and '?a=3&d=4' (or '/foo?a=3&d=4' vs '/foo/?a=3&d=4') as equivalent by default, but with an option to be more strict about slashes.
I got following error when simulate the contract with url like: http://abc.com?a=3&d=4