fluttercommunity / flutter_webview_plugin

Community WebView Plugin - Allows Flutter to communicate with a native WebView.
https://pub.dev/packages/flutter_webview_plugin
Other
1.48k stars 930 forks source link

Allow underscore middle of name in JavascriptChannel #789

Closed donguseo closed 4 years ago

donguseo commented 4 years ago

Use case

When I try to use JavascriptChannel like this. JavascriptChannel throws error.

JavascriptChannel(
  name: 'foo_action',
  onMessageReceived: (JavascriptMessage message) {
    // do something ...
  }
)

It said name is not valid. And the reason was underscore in the name of JavascriptCannel. As matter of fact, there is not any reference that JavacriptInterface does not allow underscore for javascript function name.

Proposal

I think it can be fixed with this change in javascript_channel.dart.

Before

https://github.com/fluttercommunity/flutter_webview_plugin/blob/4862bd987cf8ce6695d8d280ab407d57e5ae30f0/lib/src/javascript_channel.dart#L3-L5

After

final RegExp _validChannelNames = RegExp('^[a-zA-Z_][a-zA-Z0-9_]*\$');