Skip to content

Commit

Permalink
Remove redundant uri variations
Browse files Browse the repository at this point in the history
  • Loading branch information
uiur committed May 16, 2018
1 parent f9c09f7 commit 924c1e1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 33 deletions.
12 changes: 5 additions & 7 deletions lib/webmock/request_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class URIAddressablePattern < URIPattern
def matches?(uri)
if @query_params.nil?
# Let Addressable check the whole URI
matched_with_variations?(uri)
matches_with_variations?(uri)
else
# WebMock checks the query, Addressable checks everything else
matched_with_variations?(uri.omit(:query)) &&
matches_with_variations?(uri.omit(:query)) &&
@query_params == WebMock::Util::QueryMapper.query_to_values(uri.query)
end
end
Expand All @@ -180,13 +180,11 @@ def to_s

private

def matched_with_variations?(uri)
def matches_with_variations?(uri)
normalized_template = Addressable::Template.new(WebMock::Util::URI.heuristic_parse(@pattern.pattern))

uri_variations_with_scheme = WebMock::Util::URI.variations_of_uri_as_strings(uri)
.map {|u| WebMock::Util::URI.heuristic_parse(u) }

uri_variations_with_scheme.any? { |u| normalized_template.match(u) }
WebMock::Util::URI.variations_of_uri_as_strings(uri)
.any? { |u| normalized_template.match(u) }
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/webmock/util/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ def self.variations_of_uri_as_strings(uri_object)
uris = uris_with_inferred_port_and_without(uris)
end

if normalized_uri.scheme == "http"
uris = uris_with_scheme_and_without(uris)
end

uris.map {|uri| uri.to_s.gsub(/^\/\//,'') }.uniq
end

Expand Down
22 changes: 0 additions & 22 deletions spec/unit/util/uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

URIS_WITHOUT_PATH_OR_PARAMS =
[
"www.example.com",
"www.example.com/",
"www.example.com:80",
"www.example.com:80/",
"http://www.example.com",
"http://www.example.com/",
"http://www.example.com:80",
Expand All @@ -15,10 +11,6 @@

URIS_WITHOUT_PATH_BUT_WITH_PARAMS =
[
"www.example.com?a=b",
"www.example.com/?a=b",
"www.example.com:80?a=b",
"www.example.com:80/?a=b",
"http://www.example.com?a=b",
"http://www.example.com/?a=b",
"http://www.example.com:80?a=b",
Expand All @@ -27,18 +19,10 @@

URIS_WITH_AUTH =
[
"a b:pass@www.example.com",
"a b:pass@www.example.com/",
"a b:pass@www.example.com:80",
"a b:pass@www.example.com:80/",
"http://a b:pass@www.example.com",
"http://a b:pass@www.example.com/",
"http://a b:pass@www.example.com:80",
"http://a b:pass@www.example.com:80/",
"a%20b:pass@www.example.com",
"a%20b:pass@www.example.com/",
"a%20b:pass@www.example.com:80",
"a%20b:pass@www.example.com:80/",
"http://a%20b:pass@www.example.com",
"http://a%20b:pass@www.example.com/",
"http://a%20b:pass@www.example.com:80",
Expand All @@ -47,10 +31,6 @@

URIS_WITH_PATH_AND_PARAMS =
[
"www.example.com/my path/?a=my param&b=c d",
"www.example.com/my%20path/?a=my%20param&b=c%20d",
"www.example.com:80/my path/?a=my param&b=c d",
"www.example.com:80/my%20path/?a=my%20param&b=c%20d",
"http://www.example.com/my path/?a=my param&b=c d",
"http://www.example.com/my%20path/?a=my%20param&b=c%20d",
"http://www.example.com:80/my path/?a=my param&b=c d",
Expand All @@ -59,8 +39,6 @@

URIS_WITH_DIFFERENT_PORT =
[
"www.example.com:88",
"www.example.com:88/",
"http://www.example.com:88",
"http://www.example.com:88/"
].sort
Expand Down

0 comments on commit 924c1e1

Please sign in to comment.