apple / swift-foundation

The Foundation project
Apache License 2.0
2.29k stars 135 forks source link

Avoid crashing due to malformed paths creating URLs #646

Closed jmschonfeld closed 1 month ago

jmschonfeld commented 1 month ago

In some cases, file manager APIs may be called with malformed string paths. We correctly throw an error in those cases, but when throwing an error we try to initialize a URL from the path. In certain FOUNDATION_FRAMEWORK scenarios this leads to calling into an NSURL initializer which crashes. This code works around that crash by creating an internal failable path we can take instead when we know we're in a scenario where we may have malformed paths.

jmschonfeld commented 1 month ago

@swift-ci please test