File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -386,6 +386,9 @@ def relative(from)
386386 # An empty reference identifies the current document, so identify the current directory explicitly:
387387 if relative_segments == [ "" ]
388388 relative_segments = [ "." , "" ]
389+ elsif relative_segments . first &.include? ( ":" )
390+ # A colon in the first segment would be interpreted as a URI scheme:
391+ relative_segments . unshift ( "." )
389392 end
390393
391394 return Path . new ( nil , relative_segments )
Original file line number Diff line number Diff line change 521521 expect ( Protocol ::URL ::Path . relative ( "/docs" , "/docs/index.html" ) ) . to be == "../docs"
522522 end
523523
524+ it "disambiguates a colon in the first segment" do
525+ expect ( Protocol ::URL ::Path . relative ( "/docs/this:that" , "/docs/index.html" ) ) . to be == "./this:that"
526+ end
527+
524528 it "calculates relative path with multiple levels up" do
525529 expect ( Protocol ::URL ::Path . relative ( "/a/file.txt" , "/x/y/z/" ) ) . to be == "../../../a/file.txt"
526530 end
Original file line number Diff line number Diff line change 224224 expect ( url . relative_to ( "/index" ) . to_s ) . to be == "./?q=ruby#examples"
225225 end
226226
227+ it "disambiguates a colon in the first segment" do
228+ url = Protocol ::URL ::Relative . new ( "/docs/this:that" )
229+ relative_url = url . relative_to ( "/docs/index" )
230+
231+ expect ( relative_url . to_s ) . to be == "./this:that"
232+ expect ( Protocol ::URL [ relative_url . to_s ] ) . to be_a ( Protocol ::URL ::Relative )
233+ end
234+
227235 it "returns already-relative URLs unchanged" do
228236 url = Protocol ::URL ::Relative . new ( "../guide" , "q=ruby" , "examples" )
229237
You can’t perform that action at this time.
0 commit comments