Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential memory leak with wrong characters in event namespaces #4296

Closed
bjarketrux opened this issue Feb 11, 2019 · 1 comment
Closed

Potential memory leak with wrong characters in event namespaces #4296

bjarketrux opened this issue Feb 11, 2019 · 1 comment

Comments

@bjarketrux
Copy link

Problem

Events can have namespaces; and as according to the documentation:

"Namespaces should contain upper/lowercase letters and digits only."

If a developer does not see this particular piece of information he could create an event like this:

$(window).on("click.myNameSpace[1234]", handlerFn);

In his scenario there are several events registered and the number in brackets is forth-running. The events trigger as usual and being a good developer he also has an off method:

$(window).on(".myNameSpace[1234]");

Everything looks good, except...
After the code has been running for at while he discovered a memory leak! But why? The off function works, right? Nope (๑•́ ヮ •̀๑)

Turns out the namespace is at some point (source) turned into a regex and tested against existing events... In the case above it means that the brackets are preventing the existing events to be found and are therefore leaked for the runtime of the app.

Suggestions

First of all YES the documentation says to not use special characters, but you know that some developers does not always read the fine prints (◔_◔)

Option 1: Perhaps the on method could throw an exception if any illegal characters are entered?
Option 2: Regex-escape the namespace.

Note: I'm of cause not the developer that did not read the documentation...

@dmethvin
Copy link
Member

This was discussed in the team meeting. Since we clearly document the characters that can be in a namespace, we will leave it as-is. There is a possibility that we might use special characters for other purposes in the future, which is why the limits are there in the first place. If we regex-escape the name it allows things to work for now but removes the ability to define new syntax that uses them without randomly breaking someone's code.

@mgol mgol added wontfix and removed wontfix labels Feb 11, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants