Skip to content

Commit

Permalink
Escape Regex for search
Browse files Browse the repository at this point in the history
Fixes #191
  • Loading branch information
rvazarkar committed Jul 6, 2018
1 parent cc7412d commit ecc4286
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/components/SearchContainer/SearchContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import GlyphiconSpan from '../GlyphiconSpan';
import Icon from '../Icon';
import TabContainer from './TabContainer';
import {escapeRegExp} from 'utils';

export default class SearchContainer extends Component {
constructor(props){
Expand Down Expand Up @@ -44,6 +45,7 @@ export default class SearchContainer extends Component {
let sp = query.split(':');
let type = sp[0];
let term = sp[1];
term = escapeRegExp(term);
let t = '(?i).*' + term + '.*';

let labels = ["OU","GPO","User","Computer","Group","Domain"];
Expand Down Expand Up @@ -76,7 +78,8 @@ export default class SearchContainer extends Component {
}.bind(this));

}else{
let t = '(?i).*' + query + '.*';
let q = escapeRegExp(query);
let t = '(?i).*' + q + '.*';
let data = [];
session.run("MATCH (n) WHERE n.name =~ {name} OR n.guid =~ {name} RETURN n LIMIT 10", { name: t })
.then(function (results) {
Expand Down Expand Up @@ -260,6 +263,7 @@ export default class SearchContainer extends Component {
let sp = query.split(':');
let type = sp[0];
let term = sp[1];
term = escapeRegExp(term);
let t = '(?i).*' + term + '.*';

let labels = ["OU", "GPO", "User", "Computer", "Group", "Domain"];
Expand Down Expand Up @@ -292,7 +296,8 @@ export default class SearchContainer extends Component {
}.bind(this));

} else {
let t = '(?i).*' + query + '.*';
let q = escapeRegExp(query);
let t = '(?i).*' + q + '.*';
let data = [];
session.run("MATCH (n) WHERE n.name =~ {name} OR n.guid =~ {name} RETURN n LIMIT 10", { name: t })
.then(function (results) {
Expand Down Expand Up @@ -455,6 +460,8 @@ export default class SearchContainer extends Component {
});
}



_onPathfindClick(){
jQuery(this.refs.pathfinding).slideToggle();
var p = !this.state.pathfindingIsOpen;
Expand Down
6 changes: 5 additions & 1 deletion src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,8 @@ export function buildACLProps(rows) {
});

return datadict;
}
}

export function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

0 comments on commit ecc4286

Please sign in to comment.