Skip to content

Commit

Permalink
fix trailing text issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rantos committed Dec 4, 2021
1 parent d737f39 commit c1112fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ function sanitizeHtml(html, options, _recursing) {
result = tempResult + escapeHtml(result);
tempResult = '';
}
addedText = false;
}
}, options.parser);
parser.write(html);
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ describe('sanitizeHtml', function() {
}), '<a href="http://somelink">some good text</a>');
});

it('should preserve trailing text when replacing the tagName and adding new text via transforming function', function () {
assert.equal(sanitizeHtml('<p>text before <br> text after</p>', {
transformTags: {
br: function (_tagName, _attribs) {
return {
tagName: 'span',
text: ' '
};
}
}
}), '<p>text before <span> </span> text after</p>');
});

it('should add new text when not initially set and replace attributes when they are changed by transforming function', function () {
assert.equal(sanitizeHtml('<a href="http://somelink"></a>', {
transformTags: {
Expand Down

0 comments on commit c1112fb

Please sign in to comment.