Skip to content

Commit 84c2bd9

Browse files
committed
Add proper comments for the change
1 parent 0612d03 commit 84c2bd9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/js/_enqueues/wp/sanitize.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@
2626
let _text = text || '';
2727

2828
const domParser = new DOMParser();
29-
const htmlDocument = domParser.parseFromString( _text, 'text/html' );
29+
const htmlDocument = domParser.parseFromString(
30+
_text,
31+
'text/html'
32+
);
33+
34+
/*
35+
* This looks funny and appears to be a no-op, but it
36+
* enforces the escaping. How? when _read_ the `innerText`
37+
* property decodes character references, returning a raw
38+
* string. When _written_, however, it re-encodes to ensure
39+
* that the rendered text replicates what it’s given.
40+
*
41+
* See: https://github.com/WordPress/wordpress-develop/pull/10536#discussion_r2550615378
42+
*/
3043
htmlDocument.body.innerText = htmlDocument.body.innerText || '';
3144

3245
// Return the text with stripped tags.

0 commit comments

Comments
 (0)