KSES: Reimplement with Tag Processor - #13271
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
c784058 to
fdc5e96
Compare
bd15b3e to
38470b2
Compare
43c8868 to
54ea7dd
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
07d03c9 to
038c1c9
Compare
Co-Authored-By: Jon Surrell <jonsurrell@git.wordpress.org>
Notably, contents of SCRIPT elements _should not_ be extracted and rendered as HTML text nodes. These are SCRIPT contents, and should be hidden from the page.
…ng the original content.
|
I'm supportive of this direction overall. I'll leave some feedback on different points. I started this review at 0b1535e but it moved while I was reviewing, so some of this review may be stale by the time I post. General things to debug: echo wp_kses( '<template>foo</template>', [ 'template' => true ] );
// Prints: </template>echo wp_kses( '<div style>x</div>', [ 'div' => ['style' => true] ] );
// Prints: <div style="1">x</div>echo wp_kses( '<div style="color:red">x</div>', [ 'div' => [ 'style' => true ] ] );
// Before (trunk): <div>x</div>
// After : <div style="color:red">x</div>This is an interesting one, the block delimiter is preserved (improvement) but for some reason echo wp_kses( '<!-- wp:image {"alt":"<script>x</script>"} -->', [] );
// Before: <!-- wp:image {"alt":"x"} -->
// After: <!-- wp:core/image {"alt":""} -->Incomplete tokens are interesting. KSES would leave something like a trailing That means that partial tokens like the unclosed echo wp_kses( '<p>keep me</p><b this is lost', ['p'=>[],'b'=>[]] ) . "\n";
echo wp_kses( '<p>keep me</p><title>this is lost', ['p'=>[],'title'=>[]] ) . "\n";
echo wp_kses( '<p>keep me</p><style>*{content:"this is lost";}', ['p'=>[],'title'=>[]] ) . "\n";
echo wp_kses( '<p>keep me</p><style>*{content:"this is lost";}', ['p'=>[],'style'=>[]] ) . "\n";
echo wp_kses( '<p>keep me', ['p'=>[]] ) . "\n";Before/after diff of output: diff --git 1/tmp/before.txt 2/tmp/after.txt
index 5122acd7a7..d87549cc15 100644
--- 1/tmp/before.txt
+++ 2/tmp/after.txt
@@ -1,5 +1,5 @@
-<p>keep me</p><b this is lost
+<p>keep me</p>
-<p>keep me</p><title>this is lost
+<p>keep me</p>
-<p>keep me</p>*{content:"this is lost";}
+<p>keep me</p>
-<p>keep me</p><style>*{content:"this is lost";}
+<p>keep me</p>
<p>keep meThis is worth considering carefully. The HTML snippets KSES sees don't necessarily align with coherent boundaries. In particular We could align with the previous behavior, assume that the incomplete tokens are HTML text, and escape them as such. There may be negative implications to that, it's worth some careful consideration. Foreign content is difficult, is this a case of integration points bailing because they're risky? echo wp_kses( '<math><mtext>x</mtext></math>', ['math'=>[],'mtext'=>[]] );
// (no output)
echo wp_kses( '</br>', [ 'br' => true ] );
// Warning: foreach() argument must be of type array|object, true given in /var/www/html/wp-includes/kses.php on line 1499
// Warning: foreach() argument must be of type array|object, null given in /var/www/html/wp-includes/kses.php on line 1536
// Prints: <br>First warning is the allowed tags. I used This change produces a warning where before it did not: wordpress-develop/src/wp-includes/kses.php Line 1499 in 0b1535e Maybe wordpress-develop/src/wp-includes/kses.php Lines 1533 to 1537 in 049287a Either way, it's filterable and important to to follow whatever KSES did previously. I think if the value is Second warning is here: wordpress-develop/src/wp-includes/kses.php Line 1536 in 0b1535e As it is now, this needs a |
Trac ticket: Core-65984
Merge after #13273, which accounts for three of the failing tests.wp_kses(), it’s possible to simply wait until an opened element is closed based on depth, and skip that closing element if it exists.wp_kses()with intentionally-incomplete input, for example, a wrapper opening tag with part of the content, separately from the closer. closing open elements does a good job of isolating content, but legacy behaviors depend too much on the more procedural use ofwp_kses()so isolation cannot be reasonably added without mangling websites.pre_ksesfilters but then callpre_ksesNotes