apostrophecms / sanitize-html

Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance
MIT License
3.79k stars 353 forks source link

Content after transformTags with text option is deleted #463

Closed doncuomo closed 2 years ago

doncuomo commented 3 years ago

I changed the following spec in your code to reproduce the error:

it('should replace text and attributes when they are changed by transforming function'

See the screenshot for my change:

Screenshot 2021-02-03 at 09 51 49

Test result:

Screenshot 2021-02-03 at 09 57 02

I expect blaat to be in the result, but it's cut off

kedarchandrayan commented 2 years ago

@boutell, I tried with the snippet given in this issue. I got the expected result. Following are the findings.

code snippet:

const sanitizeHtml = require('sanitize-html');
const output = sanitizeHtml('<a href="http://somelink">some text</a> blaat', {
    transformTags: {
        a: function(tagName, attribs) {
            return {
                tagName: tagName,
                attribs: attribs,
                text: 'somelinktext'
            };
        }
    }
});

console.log(output);

Result obtained: <a href="http://somelink">somelinktext</a> blaat

We can see that the result is the same as the expected result. I think we can close this issue, saying not reproducible anymore.

boutell commented 2 years ago

Thanks for testing.

kedarchandrayan commented 2 years ago

You’re welcome.