Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighter callback errors with 'Unterminated group' #580

Open
JulesAchiel opened this issue Dec 18, 2018 · 0 comments
Open

Highlighter callback errors with 'Unterminated group' #580

JulesAchiel opened this issue Dec 18, 2018 · 0 comments

Comments

@JulesAchiel
Copy link

Our implementation has values with javascript reserved characters like open round brackets which causes atwho to error out on the highlighter callback:
Uncaught SyntaxError: Invalid regular expression:
/>\s*([^<]?)((1)([^<])\s*</: Unterminated group
at new RegExp ()
at EditableController.highlighter (:130:14)
at View.render (:1227:53)
at EditableController.Controller.renderView (:538:22)
at EditableController._callback (:624:21)
at i (:3:6336)
at Model.query (:964:14)
at EditableController.Controller._lookUp (:630:23)
at EditableController.Controller.lookUp (:577:12)
at App.dispatch (:337:22)

highlighter: function(li, query) {
var regexp;
if (!query) {
return li;
}
regexp = new RegExp(">\s*([^\<]?)(" + query.replace("+", "\+") + ")([^\<])\s*<", 'ig');
return li.replace(regexp, function(str, $1, $2, $3) {
return '> ' + $1 + '' + $2 + '' + $3 + ' <';
});

The function only escapes the + sign and not the others.

As a workaround I have overwritten the highlighter callback:
highlighter = function(li, query){
var regexp;
if (!query) {
return li;
}
query = query.replace(/[-[]/{}()*+?.\^$|]/g, "\$&");
regexp = new RegExp(">\s*([^\<]?)(" + query + ")([^\<])\s*<", 'ig');
return li.replace(regexp, function(str, $1, $2, $3) {
return '> ' + $1 + '' + $2 + '' + $3 + ' <';
});
};

This should be part of the base product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant