Skip to content
This repository was archived by the owner on Feb 26, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.17.1 (2025-09-02)

- Fix text option not being considered for transformTags when tag is *

## 2.17.0 (2025-05-14)

- Add `preserveEscapedAttributes`, allowing attributes on escaped disallowed tags to be retained. Thanks to [Ben Elliot](https://github.com/benelliott) for this new option.
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ function sanitizeHtml(html, options, _recursing) {
transformedTag = transformTagsAll(name, attribs);

frame.attribs = attribs = transformedTag.attribs;

if (transformedTag.text !== undefined) {
frame.innerText = transformedTag.text;
}

if (name !== transformedTag.tagName) {
frame.name = name = transformedTag.tagName;
transformMap[depth] = transformedTag.tagName;
Expand Down
15 changes: 14 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,23 @@ describe('sanitizeHtml', function() {
}
}), '<a href="http://somelink"></a>');
});
it('should replace text and attributes when they are changed by transforming function and textFilter is set', function () {
it('should replace text and attributes when they are changed by transforming function', function () {
assert.equal(sanitizeHtml('<a href="http://somelink">some text</a>', {
transformTags: {
a: function (tagName, attribs) {
return {
tagName: tagName,
attribs: attribs,
text: ''
};
}
}
}), '<a href="http://somelink"></a>');
});
it('should replace text and attributes for wildcard tag when they are changed by transforming function and textFilter is set', function () {
assert.equal(sanitizeHtml('<a href="http://somelink">some text</a>', {
transformTags: {
'*': function (tagName, attribs) {
return {
tagName: tagName,
attribs: attribs,
Expand Down