-
Notifications
You must be signed in to change notification settings - Fork 352
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
Trailing text is not preserved #506
Comments
Seems to be a regression. Maintainers: could you point us in the right direction as far as any guesses on where to look? We may attempt a fix. |
It sounds like it might be an upstream issue with the htmlparser2 module. Might be — haven't delved into it. |
Stumble upon the issue myself when upgraded to latest from It's a bug on transformTags on |
@alex-rantos Do you know how to fix this? |
Not really I just narrowed down the repro steps a bit further and shared it here. |
It's a regression from this commit alex-rantos@b218a72 @abea the following condition fails to append the trailing text as else if (!addedText) {
result += escaped;
} In case you take a look this is the test case that fails: 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>');
}); |
Works correctly in the version 2.6.1. Thank you for the fix! |
To Reproduce
npm install
node index.js
Expected behavior
I expect trailing text
Above
is preserved, i.e. sanitized output should be:Describe the bug
Trailing text
Above
is lost, i.e. I am getting:Details
Version of Node.js: v12.22.6
Server Operating System: Linux
Additional context:
I am trying to upgrade
sanitize-html
from version1.21.1
to latest2.5.2
(at the moment of submitting this issue) and getting the above described issue. According to my research (I have tried multiple versions) bug has appeared in version1.27.3
.The text was updated successfully, but these errors were encountered: