Skip to content

Commit

Permalink
fix: [iOS][ExpoWebBrowser] don't crash with invalid url (expo#23084)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirbod authored Jun 24, 2023
1 parent a4537e1 commit 10c961e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/expo-web-browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### 🐛 Bug fixes

- On `iOS`, fixed crash when opening an invalid URL in the web browser. ([#22986](https://github.com/expo/expo/pull/23084) by [@hirbod](https://github.com/hirbod))

### 💡 Others

## 12.3.0 — 2023-06-21
Expand Down
6 changes: 6 additions & 0 deletions packages/expo-web-browser/ios/WebBrowserExceptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ final class WebBrowserAlreadyOpenException: Exception {
"Another web browser is already open"
}
}

final class WebBrowserInvalidURLException: Exception {
override var reason: String {
return "The provided URL is not valid."
}
}
10 changes: 10 additions & 0 deletions packages/expo-web-browser/ios/WebBrowserModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ final public class WebBrowserModule: Module {
private var currentWebBrowserSession: WebBrowserSession?
private var currentAuthSession: WebAuthSession?

private func isValid(url: URL) -> Bool {
return url.scheme == "http" || url.scheme == "https"
}

public func definition() -> ModuleDefinition {
Name("ExpoWebBrowser")

AsyncFunction("openBrowserAsync") { (url: URL, options: WebBrowserOptions, promise: Promise) in
guard self.currentWebBrowserSession == nil else {
throw WebBrowserAlreadyOpenException()
}

guard self.isValid(url: url) else {
throw WebBrowserInvalidURLException()
}

self.currentWebBrowserSession = WebBrowserSession(url: url, options: options) { [promise] type in
promise.resolve(["type": type])
self.currentWebBrowserSession = nil
}

self.currentWebBrowserSession?.open()
}
.runOnQueue(.main)
Expand Down

0 comments on commit 10c961e

Please sign in to comment.