addressable icon indicating copy to clipboard operation
addressable copied to clipboard

`Addressable::URI.convert_path` normalize windows drive letter to lowercase but `Addressable::URI.parse` does not

Open edwardxia opened this issue 3 years ago • 0 comments

As title says, currently #route_to and #route_from can be broken for file:// URI due to possible inconsistency of windows drive letter casing:

irb(main):001:0> require 'addressable/uri'
=> true
irb(main):002:0> Addressable::URI.convert_path("C:\\foo.txt").route_from(Addressable::URI.parse("file:///C:/bar.txt")).to_s
=> "../c:/foo.txt"

Relevant code in question is:

https://github.com/sporkmonger/addressable/blob/dd84176c2ad6c71bbec4b66bfc694d80969149ae/lib/addressable/uri.rb#L290-L293

There is a dirty workaround by calling .convert_path on already parsed URI to apply the drive letter normalization to an already parsed URI like below:

irb(main):001:0> require 'addressable/uri'
=> true
irb(main):002:0> Addressable::URI.convert_path("C:\\foo.txt").route_from(Addressable::URI.convert_path(Addressable::URI.parse("file:///C:/bar.txt").path)).to_s
=> "foo.txt"

edwardxia avatar Feb 09 '22 09:02 edwardxia