From 298f14da1210460b3e25c6002e8d1aa5f7b4e0ef Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 12 Oct 2018 13:44:58 -0700 Subject: [PATCH] Fix crashes on invalid regex Summary: **Problem:** When you type an invalid regex into the input field of the RNTester app, it crashes. What's worse is that it remembers the input string so refreshing the view doesn't get rid of the error. Observe: https://pxl.cl/jdm3 Reviewed By: yungsters Differential Revision: D10349249 fbshipit-source-id: aab5977bd47271e9a4ff6202c93b47550da778d2 --- RNTester/js/RNTesterExampleList.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index c99b1b222..5b8071a11 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -75,7 +75,18 @@ const renderSectionHeader = ({section}) => ( class RNTesterExampleList extends React.Component { render() { const filterText = this.props.persister.state.filter; - const filterRegex = new RegExp(String(filterText), 'i'); + let filterRegex = /.*/; + + try { + filterRegex = new RegExp(String(filterText), 'i'); + } catch (error) { + console.warn( + 'Failed to create RegExp: %s\n%s', + filterText, + error.message, + ); + } + const filter = example => /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an * error found when Flow v0.68 was deployed. To see the error delete this