Skip to content

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

Open
@edwardxia

Description

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"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions