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

RequestPattern does not match domain without TLD / period since v 3.4.2 #828

Closed
eikes opened this issue Jul 10, 2019 · 4 comments
Closed

Comments

@eikes
Copy link
Contributor

eikes commented Jul 10, 2019

A Addressable::Template without a period in the domain will not be matched:

template = Addressable::Template.new('localhost:3000/api/user{?identifier}')
WebMock::API.stub_request(:get, template).to_return 'something'

I have narrowed the error down to the changes introduced in webmock version 3.4.2, before that it worked. I assume this is the commit: 2bf4453

@bblimke
Copy link
Owner

bblimke commented Jul 14, 2019

Thank you for reporting that @eikes . Since you have narrowed it down to the commit, do you know how to fix it? Would you fancy submitting a PR with the fix?

@eikes
Copy link
Contributor Author

eikes commented Jul 17, 2019

The culprit seems to be the addition of WebMock::Util::URI.heuristic_parse, which delegates to Addressable::URI.heuristic_parse which adds the http schema to the template only when the template contains a period (last case of the when statement). The WebMock::Util::URI.variations_of_uri_as_strings is called to find the match within matches_with_variations method, which DOES add the http schema to the variations, so the match is not made. So either we add the plain string without the schema to the matches_with_variations method or change the heuristic_parse method in the addressable gem to add the http schema even for hosts without a period in the name

@eikes
Copy link
Contributor Author

eikes commented Jul 18, 2019

OK, I was able to fix my problem. See the associated PR.

bblimke added a commit that referenced this issue Jul 18, 2019
…-not-matching

Failing test for issue #828: RequestPattern does not match domain without period
@bblimke
Copy link
Owner

bblimke commented Jul 18, 2019

@eikes excellent 👍 Thank you!

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

2 participants