mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
9f226416b2
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`.
12 lines
438 B
JavaScript
12 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);
|