Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
edwardxia opened this issue Feb 9, 2022 · 0 comments

Comments

@edwardxia
Copy link

edwardxia commented Feb 9, 2022

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:

# Adjust windows-style uris
uri.path.sub!(/^\/?([a-zA-Z])[\|:][\\\/]/) do
"/#{$1.downcase}:/"
end

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant