Commit 83a7a698 authored by Jacob Thornton's avatar Jacob Thornton

typeahead should escape regexp special chars

parent bf59220b
...@@ -109,7 +109,8 @@ ...@@ -109,7 +109,8 @@
} }
, highlighter: function (item) { , highlighter: function (item) {
return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) { var query = this.query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
return '<strong>' + match + '</strong>' return '<strong>' + match + '</strong>'
}) })
} }
......
...@@ -52,6 +52,22 @@ $(function () { ...@@ -52,6 +52,22 @@ $(function () {
typeahead.$menu.remove() typeahead.$menu.remove()
}) })
test("should not explode when regex chars are entered", function () {
var $input = $('<input />').typeahead({
source: ['aa', 'ab', 'ac', 'mdo*', 'fat+']
})
, typeahead = $input.data('typeahead')
$input.val('+')
typeahead.lookup()
ok(typeahead.$menu.is(":visible"), 'typeahead is visible')
equals(typeahead.$menu.find('li').length, 1, 'has 1 item in menu')
equals(typeahead.$menu.find('.active').length, 1, 'one item is active')
typeahead.$menu.remove()
})
test("should hide menu when query entered", function () { test("should hide menu when query entered", function () {
stop() stop()
var $input = $('<input />').typeahead({ var $input = $('<input />').typeahead({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment