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

feat: allow specifying a hook with removeHook() #1054

Merged
merged 1 commit into from
Dec 28, 2024

Conversation

davecardwell
Copy link
Contributor

@davecardwell davecardwell commented Dec 27, 2024

Summary

This pull request implements an optional second argument to removeHook() to allow specifying the hook function to remove.

Background & Context

Currently you can only pop hooks off the stack.

It’s a pretty straight-forward implementation and non-breaking change to allow for specifying the hook to remove.

Because DOMPurify’s hooks are global it is otherwise difficult to write code with multiple paths that may be adding hooks and tidying up after themselves. Now it can be trivially written like:

try {
  DOMPurify.addHook('afterSanitizeElements', myHook);

  // …
} finally {
  DOMPurify.removeHook('afterSanitizeElements', myHook);
}

Tasks

  • Review implementation changes
  • Confirm new test is sufficient

@cure53
Copy link
Owner

cure53 commented Dec 28, 2024

This looks great, thank you very much :)

@cure53 cure53 merged commit 0455d21 into cure53:main Dec 28, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants