1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/helpers/highlighted-text.js
Aileen Nowak 6f107a82a4 🐛 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

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