mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
6f107a82a4
closes TryGhost/Ghost#8959 - Treated the search input as a literal string rather than `RegExp` to allow characters that need escaping in `RegExp` and disable `RegExp` characterslike `|`. - Replaced any non-word characters in `highlighted-text` fn with escaped characters, so they're working with `RegExp`.
11 lines
438 B
JavaScript
11 lines
438 B
JavaScript
import {helper} from '@ember/component/helper';
|
|
import {htmlSafe} from '@ember/string';
|
|
|
|
export function highlightedText([text, termToHighlight]) {
|
|
// replace any non-word character with an escaped character
|
|
let sanitisedTerm = termToHighlight.replace(new RegExp(/\W/ig), '\\$&');
|
|
|
|
return htmlSafe(text.replace(new RegExp(sanitisedTerm, 'ig'), '<span class="highlight">$&</span>'));
|
|
}
|
|
|
|
export default helper(highlightedText);
|