]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Escape characters for RegExp matching for keyboard item matching.
authorjzaefferer <joern.zaefferer@gmail.com>
Tue, 22 Feb 2011 11:09:03 +0000 (12:09 +0100)
committerjzaefferer <joern.zaefferer@gmail.com>
Tue, 22 Feb 2011 11:09:03 +0000 (12:09 +0100)
tests/visual/menu/flyoutmenu.js

index 0485440a58a206abd0f926ac40ffb7fd7b04005b..8534c9462d57f5079b4043343b3e9df5bd660a78 100644 (file)
@@ -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) {