Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid url causing crash in ios #3384

Open
akshgods opened this issue Apr 5, 2024 · 6 comments
Open

invalid url causing crash in ios #3384

akshgods opened this issue Apr 5, 2024 · 6 comments

Comments

@akshgods
Copy link

akshgods commented Apr 5, 2024

Bug description:

If we pass invalid url we are getting crash

actual url: https://www.hindustantimes.com/ht-img/img/2024/03/27/550x309/Akshay_Kumar_1711524357605_1711524357751.jpg

invalid url which causing crash:
'%3Ca%20_blank%20href=https://www.hindustantimes.com/ht-img/img/2024/03/27/550x309/Akshay_Kumar_1711524357605_1711524357751.jpg'

Error handling functions not returning anything.

 onError={(e) => {
            console.log('onError:: ', e);

          }}
          onHttpError={(e) => {
            console.log('onHttpError:: ', e);

          }}
          renderError={(e) => {
            console.log('renderError:: ', e);
          }}

To Reproduce:

Reproduce is simple, just use this url in your webview url:

url={'%3Ca%20_blank%20href=https://www.hindustantimes.com/ht-img/img/2024/03/27/550x309/Akshay_Kumar_1711524357605_1711524357751.jpg'}

now open webview you will get application getting crash.

Expected behavior:

it should not get crashed , it will throw error in one of error handling function.

 onError={(e) => {
            console.log('onError:: ', e);

          }}
          onHttpError={(e) => {
            console.log('onHttpError:: ', e);

          }}

let me know what changes required or what we can do it to solved this?

Environment:

  • OS: Mac
  • OS version: 13.2.1 (22D68)
  • react-native version: "0.67.3"
  • react-native-webview version: "11.26.0"
@netmaxt3r
Copy link
Contributor

@akshgods can you check issue is reproducible on latest version?

@akshgods
Copy link
Author

@netmaxt3r yes confirmed with latest available version.
Simulator Screen Shot - iPhone 14 - 2024-04-15 at 13 51 03

Screenshot 2024-04-15 at 1 52 53 PM

code to test:

<WebView source={{ uri: '3Ca%20_blank%20href=https://reactnative.dev/' }} 
       style={{ flex: 1 }}
       onError={(e) => {
        console.log('onError:: ', e);
      }}
      onHttpError={(e) => {
        console.log('onHttpError:: ', e);
      }}
      renderError={(e) => {
        console.log('renderError:: ', e);
      }}
       />

Environment:

OS: Mac
OS version: 13.2.1 (22D68)
"react-native": "0.73.6",
"react-native-webview": "^13.8.5"

@netmaxt3r
Copy link
Contributor

I am getting different results.

on iOS its just console.warn with Error opening URL: [Error: Unable to open URL: ....
image
Simulator Screenshot - iPhone 15 Pro - 2024-04-15 at 20 57 40

on Android it does call onError with nativeEvent {"canGoBack": false, "canGoForward": false, "code": -2, "description": "net::ERR_NAME_NOT_RESOLVED", "loading": false, "target": 3, "title": "", "url": "http://3ca%20_blank%20href%3Dhttps//reactnative.dev/"} followed by two calls to renderError with null error
image

In either case app does not crash

@akshgods
Copy link
Author

akshgods commented Apr 16, 2024

@netmaxt3r but im getting same error as i sent before.

Simulator Screen Shot - iPhone 14 - 2024-04-16 at 13 40 08

but im not getting warning , can you share your code and url used?

also send react native version and plugin version used

@akshgods
Copy link
Author

@netmaxt3r i understand you code diffrence

you used http:// in starting of url

just use this without http:

source={{ uri: '3Ca%20_blank%20href=https://reactnative.dev/' }}

@netmaxt3r
Copy link
Contributor

@akshgods i havent added http protocol, it is added by android as the url is malformed it cannot detect the protocol, where as in ios it defaults to file protocol to relative path as seen in the warning

    return (
      <WebView source={{ uri: '3Ca%20_blank%20href=https://reactnative.dev/' }}
               style={{ flex: 1 }}
               onError={(e) => {
                 console.log('onError:: ', e.nativeEvent);
               }}
               onHttpError={(e) => {
                 console.log('onHttpError:: ', e);
               }}
               renderError={(e) => {
                 console.log('renderError:: ', e);
               }}
      />
    );
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.73.6",
    "react-native-webview": "^13.8.5"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants