Skip to content

Conversation

@jannes-mingram-lendi
Copy link

@jannes-mingram-lendi jannes-mingram-lendi commented Sep 2, 2025

Allow text option for * transformer

There seems to be a bug where the text option doesn't work with the "any-tag" option:

const clean = sanitizeHtml("<p>Hello</p>", {
  transformTags: {
    'p': function(tagName, attribs) {
      return {
        tagName: 'p',
        text: 'Some text'
      };
    }
  }
});
// <p>Some text</p>
const clean = sanitizeHtml("<p>Hello</p>", {
  transformTags: {
    '*': function(tagName, attribs) {
      return {
        tagName: tagName,
        text: 'Some text'
      };
    }
  }
});
// expected: <p>Some text</p>
// actual: <p>Hello</p>

This PR fixes the scenario above.

What are the specific steps to test this change?

See examples above

What kind of change does this PR introduce?

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

Make sure the PR fulfills these requirements:

  • It includes a clear description of the bug it resolves.
    Q: Did you want me to open a defect against the repo first, so I can reference the issue-id?
  • The changelog is updated
  • [N/A] Related documentation has been updated
  • Related tests have been updated

@jannes-mingram-lendi jannes-mingram-lendi marked this pull request as ready for review September 2, 2025 12:18
@jannes-mingram-lendi jannes-mingram-lendi changed the title support text for * transformer fix: support text for * transformer Sep 2, 2025
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.

1 participant