[wp-trac] [WordPress Trac] #64274: wp.sanitize.stripTags could rely on the browser for HTML parsing
WordPress Trac
noreply at wordpress.org
Wed Nov 19 08:10:46 UTC 2025
#64274: wp.sanitize.stripTags could rely on the browser for HTML parsing
--------------------------+-----------------------------
Reporter: dmsnell | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: General | Version:
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+-----------------------------
Comment (by hbhalodia):
Hi @westonruter @dmsnell, If I am collecting it correctly, we should
remove the usage of `regex` and use something like `DOMParser` or a simple
HTML tag via `createElement`, add it as an innerHTML and extract the
innerText from it and return that?
Something like below,
{{{
#!js
const parser = new DOMParser();
const doc = parser.parseFromString( text, 'text/html' );
return doc.body.innerText || '';
}}}
or
{{{
#!js
const element = document.createElement( 'div' );
element.innerHTML = text;
return element.innerText;
}}}
Let me know if this is something we need to update?
Thanks,
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64274#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list