Bug Tracker

Opened 9 years ago

Closed 9 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 9 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 9 years ago by dmethvin

Owner: set to dmethvin
Status: openassigned

comment:3 Changed 9 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 9 years ago by hamishdickson (previous) (diff)

comment:4 Changed 9 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[t]

    ...

    // Once for each type.namespace in types; type may be omitted
    types = ( types || "" ).match( rnotwhite ) || [ "" ];
    t = types.length;
    while ( t-- ) {
        types[t] = types[t].replace(/.+$/, "");
	tmp = rtypenamespace.exec( types[t] ) || [];
	type = origType = tmp[1];
	namespaces = ( tmp[2] || "" ).split( "." ).sort();

    ...

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

Version 0, edited 9 years ago by hamishdickson (next)

comment:5 Changed 9 years ago by hamishdickson

Pull request 1636 created for fix

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

comment:6 Changed 9 years ago by m_gol

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