Ghost/ghost/admin/app/helpers/highlighted-text.js
Aileen Nowak 9f226416b2 🐛 Fixed admin search not handling certain characters (#877)
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`.
2017-09-28 11:25:13 +01:00

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