twitter/bootstrap — Issue #2341: Typeahead errors when special characters are returned '()'
Author: thesifter
Created: 2012-03-01 00:36:26+00:00
State: open

A search that returns something like
Bob (Auckland)

eg type in bob , get Bob (Auckland) returned, then backspace to Bob (Auckland)

throws a javascript error because the regular expression fails in its grouping termination.
on the line return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match)

, highlighter: function (item) {
return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) {
return '' + match + ''
})
}

I fixed my version by escaping the regex characters as below, I'm new to Github so take it easy...

, highlighter: function (item) {
var cleanedQuery = this.query.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); // escape regex chars
return item.replace(new RegExp('(' + cleanedQuery + ')', 'ig'), function ($1, match) {
return '' + match + ''
})
}

What is the approach to getting this fixed? ideas?