Skip to content

Commit

Permalink
Ensures a filter is valid before using it for regex to prevent break (f…
Browse files Browse the repository at this point in the history
…ossasia#462)

Summary:
Checks to see if the current value put in the filter will cause visdom client to crash if used in a `string.match()` function. Thanks to OguzUzman for the catch and bug report.

Fixes fossasia#446.

Invalid regex no longer breaks the client when used in a filter

<img width="1330" alt="screen shot 2018-08-29 at 10 41 56 pm" src="https://user-images.githubusercontent.com/1276867/44826410-db961100-abdc-11e8-9d27-7ac899866c92.png">

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] For JavaScript changes, I have re-generated the minified JavaScript code.
Pull Request resolved: fossasia#462

Differential Revision: D9616244

Pulled By: JackUrb

fbshipit-source-id: 30dd46e83a18dc7b3eebe9b609e0f790af5c037e
  • Loading branch information
JackUrb authored and facebook-github-bot committed Aug 31, 2018
1 parent b7eda6e commit bd66783
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ class App extends React.Component {
return this.state.envID + '_' + key;
}

getValidFilter = (filter) => {
// Ensure the regex filter is valid
try {
'test_string'.match(filter);
} catch(e) {
filter = '';
}
return filter
}

correctPathname = () => {
var pathname = window.location.pathname;
if (pathname.indexOf('/env/') > -1) {
Expand Down Expand Up @@ -529,7 +539,7 @@ class App extends React.Component {

let sorted = sortLayout(layout);
let newPanes = Object.assign({}, this.state.panes);
let filter = this.state.filter;
let filter = this.getValidFilter(this.state.filter);
let old_sorted = sorted.slice();
let layoutID = this.state.layoutID;
let envLayoutList = this.getCurrLayoutList();
Expand Down Expand Up @@ -1147,7 +1157,8 @@ class App extends React.Component {
return null;
}
let panelayout = getLayoutItem(this.state.layout, id);
let isVisible = pane.title.match(this.state.filter)
let filter = this.getValidFilter(this.state.filter);
let isVisible = pane.title.match(filter)
return (
<div key={pane.id}
className={isVisible? '' : 'hidden-window'}>
Expand Down
Loading

0 comments on commit bd66783

Please sign in to comment.