Skip to content

Commit 298f14d

Browse files
RSNarafacebook-github-bot
authored andcommitted
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
1 parent 76bc15d commit 298f14d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

RNTester/js/RNTesterExampleList.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,18 @@ const renderSectionHeader = ({section}) => (
7575
class RNTesterExampleList extends React.Component<Props, $FlowFixMeState> {
7676
render() {
7777
const filterText = this.props.persister.state.filter;
78-
const filterRegex = new RegExp(String(filterText), 'i');
78+
let filterRegex = /.*/;
79+
80+
try {
81+
filterRegex = new RegExp(String(filterText), 'i');
82+
} catch (error) {
83+
console.warn(
84+
'Failed to create RegExp: %s\n%s',
85+
filterText,
86+
error.message,
87+
);
88+
}
89+
7990
const filter = example =>
8091
/* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an
8192
* error found when Flow v0.68 was deployed. To see the error delete this

0 commit comments

Comments
 (0)