Feature #14035
Updated by ioggstream (Roberto Polli) about 8 years ago
### Reproduce
execute URI("file:///etc/hosts").to_s
### I expect
- URI("file:///etc/hosts").to_s == "file:///etc/hosts"
- URI to preserve traditional represent file:// paths in canonical form instead converting it to the minimal one (Eg. see https://tools.ietf.org/html/rfc8089#appendix-B )
### I wish
- URI to preserve the minimal/traditional form.
URI("file:///etc/hosts").to_s == "file:///etc/hosts"
URI("file:/etc/hosts").to_s == "file:/etc/hosts"
in https://tools.ietf.org/html/rfc3986#section-1.1)
### Instead
- URI("file:///etc/hosts").to_s == "file:/etc/hosts"
- URI("file:///etc/hosts").host == nil
### Proposal Fix for Ruby 2.4
Adopting the convention of an "empty host" instead of no authority when the passed string has the traditional form.
- file schema to have a blank/empty "" host
suggested in rfc3986 will fix the issue.
```
If the URI scheme defines a default for host, then that default
applies when the host subcomponent is undefined or when the
registered name is empty (zero length). For example, the "file" URI
scheme is defined so that no authority, an empty host, and
"localhost" all mean the end-user's machine, whereas the "http"
scheme considers a missing authority or empty host invalid.
```
This is a proposed implementation.
```
require 'uri/generic'
module URI
class FILE < Generic
def initialize(*args)
super(*args)
@host = "" if @host.nil?
end
end
@@schemes['FILE'] = FILE
end
```