This repository was archived by the owner on Oct 22, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed
Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 1+ require 'uri'
2+
13module Wpxf
24 module Net
35 # Provides HTTP client functionality.
@@ -62,13 +64,11 @@ def target_host
6264 # @param parts the URI parts to join and normalize.
6365 # @return [String] a normalized URI.
6466 def normalize_uri ( *parts )
65- uri = parts * '/'
66- uri = uri . gsub ( %r{(?<!:)//} , '/' )
67- unless uri . start_with? ( '/' ) || uri . start_with? ( 'http://' ) ||
68- uri . start_with? ( 'https://' )
69- uri = '/' + uri
70- end
71- uri
67+ path = parts * '/'
68+ path = '/' + path unless path . start_with? ( '/' , 'http://' , 'https://' )
69+ url = URI . parse ( path )
70+ url . path . squeeze! ( '/' )
71+ url . to_s
7272 end
7373
7474 # Returns the base URI string.
Original file line number Diff line number Diff line change 268268 it 'joins each part specified with a forward slash' do
269269 expect ( subject . normalize_uri ( 'a' , 'uri' , 'path' ) ) . to eq '/a/uri/path'
270270 end
271+
272+ it 'removes duplicate forward slashes' do
273+ expect ( subject . normalize_uri ( 'http://localhost/' , '/path' ) ) . to eq 'http://localhost/path'
274+ end
271275 end
272276
273277 describe '#target_port' do
You can’t perform that action at this time.
0 commit comments