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

fix: allowedClasses whitelist ignored if tag is wildcard #675

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

anak-dev
Copy link

Summary

When using the * selector for a allowedClasses option, the rule is ignored if it is regex. It works if it is not regex or if the selector specifies a specific html tag. The above examples would produce the expected result if the * was replaced with a p, for example.

Closes #673

What are the specific steps to test this change?

const exampleHtml = '<p class="main-color-#4ea832">Text with color</p>';

console.log(
  sanitizeHtml(exampleHtml, {
    allowedClasses: {
      '*': [/^main-color-#[0-9A-Fa-f]{6}$/],
    },
  })
);

The result should include the class instead of removing it.

<p class="main-color-#4ea832">Text with color</p>

What kind of change does this PR introduce?

(Check at least one)

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Build-related changes
  • Other

Make sure the PR fulfills these requirements:

  • It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • The changelog is updated
  • Related documentation has been updated
  • Related tests have been updated

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.

Rules with * wildcard within allowedClasses option do not work with regex
1 participant