This repository was archived by the owner on Oct 22, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +23
-18
lines changed
Expand file tree Collapse file tree 4 files changed +23
-18
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,17 @@ def execute_delete_request(opts)
182182 def max_http_concurrency
183183 normalized_option_value ( 'max_http_concurrency' )
184184 end
185+
186+ # Normalize a relative URI into an absolute URL.
187+ # @param uri [String] the relative or absolute URI.
188+ # @return [String] the absolute URL.
189+ def normalize_relative_uri ( uri )
190+ if uri . start_with? ( '/' )
191+ normalize_uri ( full_uri , uri )
192+ else
193+ uri
194+ end
195+ end
185196 end
186197 end
187198end
Original file line number Diff line number Diff line change @@ -39,14 +39,6 @@ def create_typhoeus_request(opts)
3939 )
4040 Typhoeus ::Request . new ( normalize_relative_uri ( opts [ :url ] ) , options )
4141 end
42-
43- def normalize_relative_uri ( uri )
44- if uri . start_with? ( '/' )
45- normalize_uri ( full_uri , uri )
46- else
47- uri
48- end
49- end
5042 end
5143 end
5244end
Original file line number Diff line number Diff line change 350350 expect ( queue . length ) . to eq 2
351351 end
352352 end
353+
354+ describe '#normalize_relative_uri' do
355+ it 'joins the uri on to the value of #full_uri if it starts with a forward slash' do
356+ allow ( subject ) . to receive ( :full_uri ) . and_return ( 'http://127.0.0.1/path' )
357+ expect ( subject . normalize_relative_uri ( '/test.txt' ) ) . to eq 'http://127.0.0.1/path/test.txt'
358+ end
359+
360+ it 'uses the full url specified if it does not start with a forward slash' do
361+ allow ( subject ) . to receive ( :full_uri ) . and_return ( 'http://127.0.0.1/path' )
362+ expect ( subject . normalize_relative_uri ( 'www.github.com' ) ) . to eq 'www.github.com'
363+ end
364+ end
353365end
Original file line number Diff line number Diff line change 8686 expect ( req . url ) . to eq 'http://www.github.com/'
8787 end
8888 end
89-
90- describe '#normalize_relative_uri' do
91- it 'joins the uri on to the value of #full_uri if it starts with a forward slash' do
92- expect ( subject . normalize_relative_uri ( '/test.txt' ) ) . to eq 'http://127.0.0.1/path/test.txt'
93- end
94-
95- it 'uses the full url specified if it does not start with a forward slash' do
96- expect ( subject . normalize_relative_uri ( 'www.github.com' ) ) . to eq 'www.github.com'
97- end
98- end
9989end
You can’t perform that action at this time.
0 commit comments