Skip to content
Permalink
Browse files

Fix #13471. $().on(".xyz"...) should avoid later crash.

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.
  • Loading branch information...
dmethvin committed Feb 26, 2013
1 parent 31478b9 commit 2bbc3d5860b81e128cd92f865673e10046caac7d
Showing with 21 additions and 0 deletions.
  1. +5 −0 src/event.js
  2. +16 −0 test/unit/event.js
@@ -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 ] || {};
@@ -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

This comment has been minimized.

@staabm

staabm Feb 26, 2013

Contributor

. missing?

This comment has been minimized.

@dmethvin

dmethvin Feb 26, 2013

Author Member

no that was intentional, i wanted to see if it triggered the event.

This comment has been minimized.

@gibson042

gibson042 Feb 27, 2013

Member

We probably should trigger a dummy.whoops or something, though, to make sure that the handler is truly a no-op.

.off(".whoops")
.trigger("whoops") // 2
.off("whoops");
});

test("bind(), with same function", function() {
expect(2);

0 comments on commit 2bbc3d5

Please sign in to comment.
You can’t perform that action at this time.