Skip to content

Commit

Permalink
fix: escape regexp from query (#2273)
Browse files Browse the repository at this point in the history
* fix: escape regexp from query
  • Loading branch information
fengkx authored Aug 28, 2020
1 parent fe718a1 commit 2caa5cf
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion js/src/forum/components/DiscussionListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import slidable from '../utils/slidable';
import extractText from '../../common/utils/extractText';
import classList from '../../common/utils/classList';

import { escapeRegExp } from 'lodash-es';
/**
* The `DiscussionListItem` component shows a single discussion in the
* discussion list.
Expand Down Expand Up @@ -72,7 +73,7 @@ export default class DiscussionListItem extends Component {
jumpTo = post.number();
}

const phrase = this.props.params.q;
const phrase = escapeRegExp(this.props.params.q);
this.highlightRegExp = new RegExp(phrase + '|' + phrase.trim().replace(/\s+/g, '|'), 'gi');
} else {
jumpTo = Math.min(discussion.lastPostNumber(), (discussion.lastReadPostNumber() || 0) + 1);
Expand Down

0 comments on commit 2caa5cf

Please sign in to comment.