Highlighter callback errors with 'Unterminated group'
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 (
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.