At.js icon indicating copy to clipboard operation
At.js copied to clipboard

Highlighter callback errors with 'Unterminated group'

Open JulesAchiel opened this issue 7 years ago • 0 comments

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.

JulesAchiel avatar Dec 18 '18 23:12 JulesAchiel