1
0
mirror of https://github.com/flarum/core.git synced 2025-01-18 06:38:25 +01:00

fix: escape regexp from query (#2273)

* fix: escape regexp from query
This commit is contained in:
fengkx 2020-08-28 10:39:49 +08:00 committed by GitHub
parent fe718a1490
commit 2caa5cf19c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.
@ -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);