https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-05-18T15:37:23ZRuby Issue Tracking SystemRuby master - Feature #15861: Correctly parse `file:c:/path/to/file` URIshttps://redmine.ruby-lang.org/issues/15861?journal_id=780702019-05-18T15:37:23Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>Looking at RFC 8089, Appendix E (<code>Nonstandard Syntax Variations</code>) states:</p>
<pre><code> These variations may be encountered by existing usages of the file
URI scheme but are not supported by the normative syntax of
Section 2.
This appendix is not normative.
</code></pre>
<p>Appendix E.2 says that the following form is already supported: <code>file:///c:/path/to/file</code>. Using that with the URI library:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">URI</span><span class="p">.</span><span class="nf">parse</span><span class="p">(</span><span class="s2">"file:///c:/path/to/file"</span><span class="p">).</span><span class="nf">path</span>
<span class="o">=></span> <span class="s2">"/c:/path/to/file"</span>
</code></pre>
<p>I can see where the preceding <code>/</code> may present an issue. However, I am not sure whether we want to add support for nonstandard syntax variations to the <code>file</code> scheme.</p> Ruby master - Feature #15861: Correctly parse `file:c:/path/to/file` URIshttps://redmine.ruby-lang.org/issues/15861?journal_id=780712019-05-18T16:02:12Zdeivid (David RodrÃguez)
<ul></ul><p>Yep, that's correct.</p>
<p>The alternative is to use the alternative form, but as you point out, the preceding slash is certainly inconvenient.</p>
<p>Anyways, thanks for considering this.</p> Ruby master - Feature #15861: Correctly parse `file:c:/path/to/file` URIshttps://redmine.ruby-lang.org/issues/15861?journal_id=780722019-05-18T16:05:40Zdeivid (David RodrÃguez)
<ul></ul><p>This is definitely intentional behavior, by the way. This is how the current tests look:</p>
<pre><code> u = URI("file:///c:/path/to/file")
assert_equal "/c:/path/to/file", u.path
# this form is not supported
u = URI("file:c:/path/to/file")
assert_equal "c:/path/to/file", u.opaque
</code></pre>
<p>I just wished working with file URIs on Windows was a bit easier.</p> Ruby master - Feature #15861: Correctly parse `file:c:/path/to/file` URIshttps://redmine.ruby-lang.org/issues/15861?journal_id=780752019-05-18T22:58:30Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>jeremyevans0 (Jeremy Evans) wrote:</p>
<blockquote>
<p>Looking at RFC 8089, Appendix E (<code>Nonstandard Syntax Variations</code>) states:</p>
<pre><code> These variations may be encountered by existing usages of the file
URI scheme but are not supported by the normative syntax of
Section 2.
This appendix is not normative.
</code></pre>
</blockquote>
<p>"may be encountered" here is meant to mean that old "poorly formed" URIs exist in the wild, and occasionally we encounter them. For example, if I were to write a Ruby script to update a bunch of historical documentation from 1997. It can also mean the kind of stuff humans input, which "worked for me when I did it in Internet Explorer".</p>
<blockquote>
<p>Appendix E.2 says that the following form is already supported: <code>file:///c:/path/to/file</code>. Using that with the URI library:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">URI</span><span class="p">.</span><span class="nf">parse</span><span class="p">(</span><span class="s2">"file:///c:/path/to/file"</span><span class="p">).</span><span class="nf">path</span>
<span class="o">=></span> <span class="s2">"/c:/path/to/file"</span>
</code></pre>
</blockquote>
<p>In other words, implement a pre-parser that detects E.2-flavoured URIs and inserts the extra slash. FWIW there's actually a <a href="https://phluid61.github.io/file-uri/" class="external">gem</a> out there that does essentially this, however since it was written and published alongside RFC 8089 it predates the core File URI handling.</p>
<pre><code>require 'file-uri/win'
URI.parse("file:c:/path/to/file").path
=> "/c:/path/to/file"
</code></pre>
<blockquote>
<p>I can see where the preceding <code>/</code> may present an issue. However, I am not sure whether we want to add support for nonstandard syntax variations to the <code>file</code> scheme.</p>
</blockquote>
<p>It's a pain, but it's a pain we've lived with forever. FWIW, I added a <code>#to_file_path</code> method in that gem to see if it makes this particular paint point any easier. But I don't think this is the major driver, more it's having to detect and correct those other URIs.</p>
<p>All said; if all else fails there's always Addressable.</p> Ruby master - Feature #15861: Correctly parse `file:c:/path/to/file` URIshttps://redmine.ruby-lang.org/issues/15861?journal_id=899012021-01-13T04:17:11Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/14035">Feature #14035</a>: URI module always serializes to the minimal form insted of the traditional one</i> added</li></ul>