Skip to content

Commit a68ef43

Browse files
committed
Update trustedURL methot to crash if needed
1 parent 1d02957 commit a68ef43

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

WooCommerce/Classes/System/WooConstants.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,14 @@ private extension WooConstants.URLs {
270270
/// Convert a `string` to a `URL`. Crash if it is malformed.
271271
///
272272
private static func trustedURL(_ url: String) -> URL {
273-
guard let url = URL(string: url) else {
274-
let fallback = URL(string: url.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) ?? "")
275-
return fallback ?? URL(string: "")!
273+
274+
if let url = URL(string: url) {
275+
return url
276+
} else if let escapedString = url.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed),
277+
let escapedURL = URL(string: escapedString) {
278+
return escapedURL
279+
} else {
280+
fatalError("Expected URL \(url) to be a well-formed URL.")
276281
}
277-
return url
278282
}
279283
}

0 commit comments

Comments
 (0)