Skip to content

Commit

Permalink
Fix crashes on invalid regex
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Oct 12, 2018
1 parent 76bc15d commit 298f14d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion RNTester/js/RNTesterExampleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ const renderSectionHeader = ({section}) => (
class RNTesterExampleList extends React.Component<Props, $FlowFixMeState> {
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
Expand Down

0 comments on commit 298f14d

Please sign in to comment.