diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba3de1..7ec3c55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## UNRELEASED + +- Fixed trailing text bug on `transformTags` options that was reported on [issue #506](https://github.com/punkave/sanitize-html/issues/506). Thanks to [Alex Rantos](https://github.com/alex-rantos). + ## 2.6.0 (2021-11-23) - Support for regular expressions in the `allowedClasses` option. Thanks to [Alex Rantos](https://github.com/alex-rantos). diff --git a/index.js b/index.js index ed87028..3f0ff55 100644 --- a/index.js +++ b/index.js @@ -582,6 +582,7 @@ function sanitizeHtml(html, options, _recursing) { result = tempResult + escapeHtml(result); tempResult = ''; } + addedText = false; } }, options.parser); parser.write(html); diff --git a/test/test.js b/test/test.js index 9dddc7a..5b343c1 100644 --- a/test/test.js +++ b/test/test.js @@ -228,6 +228,19 @@ describe('sanitizeHtml', function() { }), 'some good text'); }); + it('should preserve trailing text when replacing the tagName and adding new text via transforming function', function () { + assert.equal(sanitizeHtml('
text before
text after
text before text after
'); + }); + it('should add new text when not initially set and replace attributes when they are changed by transforming function', function () { assert.equal(sanitizeHtml('', { transformTags: {