Opened 9 years ago
Closed 9 years ago
#15073 closed bug (migrated)
Infinite Loop in .off() with empty namespace
Reported by: | 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
Component: | unfiled → event |
---|---|
Milestone: | None → 1.12/2.2 |
Priority: | undecided → low |
Status: | new → open |
comment:2 Changed 9 years ago by
Owner: | set to dmethvin |
---|---|
Status: | open → assigned |
comment:3 Changed 9 years ago by
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
comment:4 Changed 9 years ago by
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
comment:6 Changed 9 years ago by
Resolution: | → migrated |
---|---|
Status: | assigned → closed |
Migrated to https://github.com/jquery/jquery/issues/1769
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.