]> source.dussan.org Git - jquery.git/commitdiff
Fix #13471. $().on(".xyz"...) should avoid later crash.
authorDave Methvin <dave.methvin@gmail.com>
Tue, 26 Feb 2013 17:19:04 +0000 (12:19 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Tue, 26 Feb 2013 17:19:09 +0000 (12:19 -0500)
If the event type is an empty string we end up hanging in .off() which makes for
mighty hard debugging. Instead treat it as a no-op. Docs seem clear this is not
allowed.

src/event.js
test/unit/event.js

index 4266a1ddbb66a02cecebf5a187a118a8dbda8d9c..8a52c60ea2b9f542b7a651c503bf3b68bd2279d8 100644 (file)
@@ -66,6 +66,11 @@ jQuery.event = {
                        tmp = rtypenamespace.exec( types[t] ) || [];
                        type = origType = tmp[1];
                        namespaces = ( tmp[2] || "" ).split( "." ).sort();
+                       
+                       // There *must* be a type, no attaching namespace-only handlers
+                       if ( !type ) {
+                               continue;
+                       }
 
                        // If event changes its type, use the special event handlers for the changed type
                        special = jQuery.event.special[ type ] || {};
index 6be4eb8e7301426d171664f9624d40628cd498de..97c29ffeffdb14b33c07932a991f3495a91a4036 100644 (file)
@@ -555,6 +555,22 @@ test("bind(), multi-namespaced events", function() {
        jQuery("#firstp").trigger("custom");
 });
 
+test("namespace-only event binding is a no-op", function(){
+       expect(2);
+
+       jQuery("#firstp")
+               .on( ".whoops", function() {
+                       ok( false, "called a namespace-only event" );
+               })
+               .on( "whoops", function() {
+                       ok( true, "called whoops" );
+               })
+               .trigger("whoops")      // 1
+               .off(".whoops")
+               .trigger("whoops")      // 2
+               .off("whoops");
+});
+
 test("bind(), with same function", function() {
        expect(2);