Bug Tracker

Opened 6 years ago

Closed 5 years ago

#15073 closed bug (migrated)

Infinite Loop in .off() with empty namespace

Reported by: Christian Meixner <christian@…> Owned by: dmethvin
Priority: low Milestone: 1.12/2.2
Component: event Version: 1.11.0
Keywords: Cc:
Blocked by: Blocking:

Description

IF there is an event registered with namespace and you try to remove this with an an accidentally empty namespace-string, then .off() enters an inifinite loop, locking up the browser window (at least on Firefox).

Example: $(document).on('click.a', handler), $(document).off('click.');

Note the trailing dot after "click"!

I am aware that this is not valid code, but it should not fail with an infinite loop blocking the browser.

Change History (6)

comment:1 Changed 6 years ago by dmethvin

Component: unfiledevent
Milestone: None1.12/2.2
Priority: undecidedlow
Status: newopen

Yeah, an infinite loop seems like a bad outcome. I suppose it should just ignore a trailing dot as if there were no namespaces at all.

comment:2 Changed 6 years ago by dmethvin

Owner: set to dmethvin
Status: openassigned

comment:3 Changed 5 years ago by hamishdickson

For completeness I've created a quick jsFiddle for this here http://jsfiddle.net/EJTyW/5/

Christian is right, this is a problem in Firefox but Chrome and Safari both handle it (in that they don't loop forever)

I will have a look and see what we can do about it

Last edited 5 years ago by hamishdickson (previous) (diff)

comment:4 Changed 5 years ago by hamishdickson

After some digging about, this actually looks to be an issue with remove(), rather than off(). So it could cause problems elsewhere.

If we go with the idea that it should just ignore a trailing dot as if there were no namespaces at all, then it's just a case of stripping out any trailing dots in types before it gets to the while loop

    ...

    // remove any trailing dots
    types = types.replace(/\.+\s/, " ").replace(/\.+$/, ""); 

    // Once for each type.namespace in types; type may be omitted
    types = ( types || "" ).match( rnotwhite ) || [ "" ];
    t = types.length;
    while ( t-- ) {
	tmp = rtypenamespace.exec( types[t] ) || [];

    ...

I've run the unit tests over this and I don't get any errors. I also can't think of a reason why it would be valid to have a trailing dot. I will do a proper test tomorrow and submit a pull request unless anyone has any comments on style or logic

Last edited 5 years ago by hamishdickson (previous) (diff)

comment:5 Changed 5 years ago by hamishdickson

Pull request 1636 created for fix

Last edited 5 years ago by hamishdickson (previous) (diff)

comment:6 Changed 5 years ago by m_gol

Resolution: migrated
Status: assignedclosed
Note: See TracTickets for help on using tickets.