From: jzaefferer Date: Tue, 22 Feb 2011 11:09:03 +0000 (+0100) Subject: Menu: Escape characters for RegExp matching for keyboard item matching. X-Git-Tag: 1.9m5~296 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=68c13cd6a624b145ccf9a585baaea0aa36eff60c;p=jquery-ui.git Menu: Escape characters for RegExp matching for keyboard item matching. --- diff --git a/tests/visual/menu/flyoutmenu.js b/tests/visual/menu/flyoutmenu.js index 0485440a5..8534c9462 100644 --- a/tests/visual/menu/flyoutmenu.js +++ b/tests/visual/menu/flyoutmenu.js @@ -57,15 +57,17 @@ $.widget("ui.flyoutmenu", { } else { character = prev + character; } - + function escape(value) { + return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + } var match = self.activeItem.parent("ul").children("li").filter(function() { - return new RegExp("^" + character, "i").test($("a", this).text()); + return new RegExp("^" + escape(character), "i").test($("a", this).text()); }); var match = skip && match.index(self.active.next()) != -1 ? match.next() : match; if (!match.length) { character = String.fromCharCode(event.keyCode); match = self.widget().children("li").filter(function() { - return new RegExp("^" + character, "i").test($(this).text()); + return new RegExp("^" + escape(character), "i").test($(this).text()); }); } if (match.length) {