🐛 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`.
This commit is contained in:
Aileen Nowak 2017-09-28 17:25:13 +07:00 committed by Kevin Ansfield
parent 382e65aedc
commit 9f226416b2
2 changed files with 6 additions and 3 deletions

View File

@ -14,9 +14,9 @@ export function computedGroup(category) {
}
return this.get('content').filter((item) => {
let search = new RegExp(this.get('currentSearch'), 'ig');
let search = this.get('currentSearch').toString().toLowerCase();
return (item.category === category) && item.title.match(search);
return (item.category === category) && (item.title.toString().toLowerCase().indexOf(search) >= 0);
});
});
}

View File

@ -2,7 +2,10 @@ import {helper} from '@ember/component/helper';
import {htmlSafe} from '@ember/string';
export function highlightedText([text, termToHighlight]) {
return htmlSafe(text.replace(new RegExp(termToHighlight, 'ig'), '<span class="highlight">$&</span>'));
// 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);