<div dir="ltr">So are you saying we need <i>three</i> distinct “URI” types for local-absolute, local-relative, and remote? That’s a lot of API surface to support.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 22, 2017 at 12:24 PM, Dave DeLong <span dir="ltr"><<a href="mailto:delong@apple.com" target="_blank">delong@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I completely agree. URL packs a lot of punch, but IMO it’s the wrong abstraction for file system paths.<div><br></div><div>I maintain an app that deals a <i>lot</i> with file system paths, and using URL has always felt cumbersome, but String is the absolute wrong type to use. Lately as I’ve been working on it, I’ve been experimenting with a concrete “Path” type, similar to PathKit (<a href="https://github.com/kylef/PathKit/" target="_blank">https://github.com/kylef/<wbr>PathKit/</a>). Working in terms of AbsolutePath and RelativePath (what I’ve been calling things) has been <i>extremely</i> refreshing, because it allows me to better articulate the kind of data I’m dealing with. URL doesn’t handle pure-relative paths very well, and it’s always a bit of a mystery how resilient I need to be about checking .isFileURL or whatever. All the extra properties (port, user, password, host) feel hugely unnecessary as well.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Dave</div></font></span><div><div class="h5"><div><br><div><blockquote type="cite"><div>On Aug 20, 2017, at 11:23 PM, Félix Cloutier via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-2591326461211282683Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>I'm not convinced that URLs are the appropriate abstraction for a file system path. For the record, I'm not a fan of existing Foundation methods that create objects from an URL. There is a useful and fundamental difference between a local path and a remote path, and conflating the two has been a security pain point in many languages and frameworks that allow it. Examples include remote file inclusion in PHP and malicious doctypes in XML. Windows also had its share of issues with UNC paths.</div><div><br></div><div>Even when loading an arbitrary URL looks innocuous, many de-anonymizing hacks work by causing a program to access an URL controlled by an attacker to make it disclose the user's IP address or some other identifier.</div><div><br></div><div>IMO, this justifies that there should be separate types to handle local and remote resources, so that at least developers have to be explicit about allowing remote resources. This makes a new URL type less necessary towards supporting file I/O.</div><div><br></div><div>Félix</div><br><div><blockquote type="cite"><div>Le 20 août 2017 à 21:37, Taylor Swift via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br class="m_-2591326461211282683Apple-interchange-newline"><div><div dir="ltr"><div><div>Okay so a few days ago there was a <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170814/038923.html" target="_blank">discussion</a> about getting pure swift file system support into Foundation or another core library, and in my opinion, doing this requires a total overhaul of the `<span style="font-family:monospace,monospace">URL</span>` type (which is currently little more than a wrapper for NSURL), so I’ve just started a pure Swift URL library project at <<a href="https://github.com/kelvin13/url" target="_blank">https://github.com/kelvin13/<wbr>url</a>>.<br><br></div>The library’s parsing and validation core (~1K loc pure swift) is already in place and functional; the goal is to eventually support all of the Foundation URL functionality.</div><div><br></div><div>The new `URL` type is implemented as a value type with utf8 storage backed by an array buffer. The URLs are just 56 bytes long each, so they should be able to fit into cache lines. (NSURL by comparison is over 128 bytes in size; it’s only saved by the fact that the thing is passed as a reference type.)<br></div><div><br></div>As I said, this is still really early on and not a mature library at all but everyone is invited to observe, provide feedback, or contribute!<br></div>
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div></blockquote></div><br></div>______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>