flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.16k stars 27.44k forks source link

When using "url_launcher" plugin, if the urlString is illegal or Unusual, [NSURL URLWithString:urlString] = nil, calling the canOpenURL method will crash. #72704

Closed Eddiegooo closed 3 years ago

Eddiegooo commented 3 years ago

iOS system, use OC language, When using "url_launcher" plugin, if the urlString is illegal or Unusual, so [NSURL URLWithString:urlString] = nil, calling the canOpenURL method will crash.

eg: urlString = "https://baijiahao.baidu.com/s?id=1686309037418242167&wfr=spider&for=pc随便加点中文", NSURL *url = [NSURL URLWithString:urlString]; the url == nil, calling the "canOpenURL" method crash.

darshankawar commented 3 years ago

@Eddiegooo Please provide flutter doctor -v and a complete reproducible code sample that we can use to replicate the issue you are facing. Thanks.

Eddiegooo commented 3 years ago

@Eddiegooo Please provide flutter doctor -v and a complete reproducible code sample that we can use to replicate the issue you are facing. Thanks.

[✓] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.4 19E287 darwin-x64, locale zh-Hans-CN) • Flutter version 1.22.4 at /Users/**/Fan/Work/FlutterSoure/flutter • Framework revision 1aafb3a8b9 (6 weeks ago), 2020-11-13 09:59:28 -0800 • Engine revision 2c956a31c0 • Dart version 2.10.4 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at /Users/**/Library/Android/sdk • Platform android-29, build-tools 29.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 11.4.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.4.1, Build version 11E503a ! CocoaPods 1.7.5 out of date (1.8.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade: sudo gem install cocoapods

[✓] Android Studio (version 4.0) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin installed • Dart plugin version 193.7547 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (1 available) • iPhone 11 Pro Max (mobile) • B6406776-E8D2-4D10-962C-5526CF517717 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)

darshankawar commented 3 years ago

@Eddiegooo We will also need a minimal complete reproducible code sample as requested earlier, that we can copy paste and run to see the issue you are seeing. Thanks.

Eddiegooo commented 3 years ago

@Eddiegooo We will also need a minimal complete reproducible code sample as requested earlier, that we can copy paste and run to see the issue you are seeing. Thanks.

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _incrementCounter() async {
    String specialString =
        "https://baijiahao.baidu.com/s?id=1686309037418242167&wfr=spider&for=pc随便加点中文";
    if (await canLaunch(specialString)) {
      await launch(specialString);
    } else {
      throw 'can not open $specialString';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[Text("Test url launcher")],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
Eddiegooo commented 3 years ago

i try to fix it! fix url == nil

darshankawar commented 3 years ago

@Eddiegooo Tried your code sample on latest master, but didn't see the crash, although the url provided returned with:

Screenshot 2020-12-23 at 2 40 41 PM
flutter doctor -v ``` [✓] Flutter (Channel master, 1.26.0-2.0.pre.117, on Mac OS X 10.15.4 19E2269 darwin-x64, locale en-IN) • Flutter version 1.26.0-2.0.pre.117 at /Users/dhs/documents/Fluttersdk/flutter • Framework revision 15c009b805 (7 hours ago), 2020-12-22 20:09:03 -0500 • Engine revision b7cd3f8e70 • Dart version 2.12.0 (build 2.12.0-173.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0) • Android SDK at /Users/dhs/Library/Android/sdk • Platform android-30, build-tools 30.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 12.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.0.1, Build version 12A7300 ! CocoaPods 1.9.3 out of date (1.10.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.0) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 46.0.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] VS Code (version 1.51.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.16.0 [✓] Connected device (4 available) • SM A260G (mobile) • 5200763ebcfa861f • android-arm • Android 8.1.0 (API 27) • iPhone SE (2nd generation) (mobile) • 6C85835D-FBFD-4AB3-8DE8-B4FAD35E5367 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88 ! Doctor found issues in 1 category. ```

Do you see the crash by running the code you provided ? or we need to use any other url to replicate the crash ?

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.