proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.32k stars 227 forks source link

Prevent iOS crash when redirect url is null #286

Closed rmartin48 closed 2 years ago

rmartin48 commented 3 years ago

PR Checklist

What is the current behavior?

On iOS, calling openAuth with undefined/null for redirectUrl will crash the app. This issue was recently introduced in this commit where the scheme is being extracted from the redirect url. The result is that escapedRedirectURL = "<null>" which is not a valid URL scheme.

ExceptionsManager.js:179 Exception '*** -[NSURL initWithString:relativeToURL:]: nil string parameter' was thrown while invoking openAuth on target RNInAppBrowser with params (
    "https://xxx.xxx.amazoncognito.com/logout?client_id=xxx&logout_uri=myscheme%3A%2F%2Fpath",
    "<null>",
       ...

What is the new behavior?

Don't attempt to extract the scheme from redirectUrl if it is undefined. Simply pass in nil which will be handled gracefully.

jdnichollsc commented 3 years ago

Why redirectUrl is null? I mean, this parameter is not optional 🤔

jdnichollsc commented 3 years ago

I'm asking because that url is required for Android platform as you can see here https://github.com/proyecto26/react-native-inappbrowser/blob/develop/utils.js#L31

deermichel commented 3 years ago

I don't know why it's null, but we encounter the same crashes on iOS 👍🏽

jdnichollsc commented 3 years ago

Please create an issue related to this PR and attach a reproducible demo to understand better your scenario 👍

jdnichollsc commented 2 years ago

Thanks for your contribution mate! <3