Skip to content

Commit ee1a608

Browse files
authored
(141549683) Restore behavior of URL(string: "") returning nil (#1103)
1 parent b01f9c6 commit ee1a608

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

Sources/FoundationEssentials/URL/URL.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,20 +777,13 @@ public struct URL: Equatable, Sendable, Hashable {
777777
///
778778
/// Returns `nil` if a `URL` cannot be formed with the string (for example, if the string contains characters that are illegal in a URL, or is an empty string).
779779
public init?(string: __shared String) {
780+
guard !string.isEmpty else { return nil }
780781
#if FOUNDATION_FRAMEWORK
781782
guard foundation_swift_url_enabled() else {
782-
guard !string.isEmpty, let inner = NSURL(string: string) else { return nil }
783+
guard let inner = NSURL(string: string) else { return nil }
783784
_url = URL._converted(from: inner)
784785
return
785786
}
786-
// Linked-on-or-after check for apps which pass an empty string.
787-
// The new URL(string:) implementations allow the empty string
788-
// as input since an empty path is valid and can be resolved
789-
// against a base URL. This is shown in the RFC 3986 examples:
790-
// https://datatracker.ietf.org/doc/html/rfc3986#section-5.4.1
791-
if Self.compatibility1 && string.isEmpty {
792-
return nil
793-
}
794787
#endif // FOUNDATION_FRAMEWORK
795788
guard let parseInfo = Parser.parse(urlString: string, encodingInvalidCharacters: true) else {
796789
return nil

0 commit comments

Comments
 (0)