I'm happy to announce that WebURL 0.2.0 is out now!
Check it out: [Repository]
What's Changed
In addition to the changes listed below, the guide has been entirely rewritten, and now does a better job of explaining the WebURL API and object model, and the benefits it can bring to your application/library. The goal is to help you become as comfortable using WebURL
as you are using Foundation's URL
. It took a lot of work, and I'd really recommend giving it a read. Even if you're not using WebURL
yet, the chances are that you'll learn a thing or two about how Foundation's URL
actually works.
URL standard
- Domains which end in numbers must be IPv4 addresses. See here for more information. (https://github.com/whatwg/url/pull/619)
- The JavaScript model's
hostname
setter now returns early if a port is given. (Make hostname state return early if a port is given by TimothyGu · Pull Request #604 · whatwg/url · GitHub) - The
path
setter can no longer erase the path of path-only URLs. (Prevent the pathname setter from erasing the path of path-only URLs, … by karwa · Pull Request #582 · whatwg/url · GitHub) (reported by us)
API
- Support for creating file URLs from file paths, and file paths from file URLs.
- Added
WebURLSystemExtras
module which integrates with bothswift-system
and Apple'sSystem.framework
. -
LazilyPercentDecoded<Collection>
is now bidirectional when its source collection is. -
WebURL.cannotBeABase
has been renamed toWebURL.hasOpaquePath
, following an update in the standard. (Editorial: fold cannot-be-base-URL into path by annevk · Pull Request #655 · whatwg/url · GitHub) (reported by us) - Percent-encoding and -decoding APIs have been reworked to take advantage of static member syntax (SE-0299). A source-compatible fallback is in place for pre-5.5 compilers. This is the reason for duplicate functions appearing in the docs, one with a
EncodeSet._Member
argument. We're looking at moving to Swift-DocC which will hopefully fix this. The previous API has been back-ported with deprecation notices wherever possible, so the compiler should guide when it comes to updating your applications. - It is now possible to percent-decode a string as an array of bytes using the
.percentDecodedBytesArray()
function. This is useful for dealing with binary data and non-UTF8 strings. - The
.pathComponents
view now assumes inserted data is not percent-encoded, which preserves values exactly if they happen to contain strings which coincidentally look like percent-encoding. - A
.pathComponents[raw: Index]
subscript has been added, which returns a path component exactly as it appears in the URL string, including its percent-encoding. - A
.pathComponent.replaceSubrange(_:withPercentEncodedComponents:)
function has been added for inserting pre-encoded path components. - Added
Sendable
conformance toWebURL
,WebURL.Host
, IP addresses, origins, and the various wrapper views. - The
.serialized
property has been combined with.serializedExcludingFragment
in to a single function:.serialized(excludingFragment: Bool = false)
.
Implementation
- Better performance, especially for component setters
- Component setters are now benchmarked
- Support for fuzzing the parser
- Added
UnsafeBoundsCheckedBufferPointer
which allows us to keep bounds-checking without sacrificing performance - Simplified internal storage types, reducing code size
- Better percent-encoding performance
Full Changelog: Comparing 0.1.0...0.2.0 · karwa/swift-url · GitHub
What's coming next
The major goal for 0.3.0 is compatibility with Foundation's URL
. At the very least, that is going to include support for creating a URL
from a WebURL
and vice versa, but we may need additional APIs for a truly great developer experience.