Skip to content

Commit ecf64d6

Browse files
committed
fix(windows-path): prevent locale file paths to be parsed by URI to stop errors in windows paths like spaces in paths
1 parent 3e9895a commit ecf64d6

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

lib/pact/consumer_contract/pact_file.rb

+21-25
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,25 @@ def save_pactfile_to_tmp pact, name
3636
end
3737

3838
def render_pact(uri_string, options)
39-
uri_obj = URI(windows_safe(uri_string))
40-
if uri_obj.userinfo
41-
options[:username] = uri_obj.user unless options[:username]
42-
options[:password] = uri_obj.password unless options[:password]
43-
end
44-
get(uri_obj, options)
39+
local?(uri_string) ? get_local(uri_string, options) : get_remote_with_retry(uri_string, options)
4540
end
4641

4742
private
48-
49-
def get(uri, options)
50-
local?(uri) ? get_local(uri, options) : get_remote_with_retry(uri, options)
51-
end
52-
43+
5344
def local? uri
54-
!uri.host
45+
!uri.start_with?("http://", "https://")
5546
end
5647

57-
def get_local(uri, _)
58-
File.read uri.to_s
48+
def get_local(filepath, _)
49+
File.read windows_safe(filepath)
5950
end
6051

61-
def get_remote(uri, options)
62-
request = Net::HTTP::Get.new(uri)
63-
request.basic_auth(options[:username], options[:password]) if options[:username]
64-
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
65-
http.open_timeout = options[:open_timeout] || OPEN_TIMEOUT
66-
http.read_timeout = options[:read_timeout] || READ_TIMEOUT
67-
http.request(request)
68-
end
69-
end
70-
71-
def get_remote_with_retry(uri, options)
52+
def get_remote_with_retry(uri_string, options)
53+
uri = URI(uri_string)
54+
if uri.userinfo
55+
options[:username] = uri.user unless options[:username]
56+
options[:password] = uri.password unless options[:password]
57+
end
7258
((options[:retry_limit] || RETRY_LIMIT) + 1).times do |i|
7359
begin
7460
response = get_remote(uri, options)
@@ -88,6 +74,16 @@ def get_remote_with_retry(uri, options)
8874
end
8975
end
9076
end
77+
78+
def get_remote(uri, options)
79+
request = Net::HTTP::Get.new(uri)
80+
request.basic_auth(options[:username], options[:password]) if options[:username]
81+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
82+
http.open_timeout = options[:open_timeout] || OPEN_TIMEOUT
83+
http.read_timeout = options[:read_timeout] || READ_TIMEOUT
84+
http.request(request)
85+
end
86+
end
9187

9288
def success?(response)
9389
response.code.to_i == 200

0 commit comments

Comments
 (0)