mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
🐛 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:
parent
382e65aedc
commit
9f226416b2
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user