-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HTML API: set_modifiable_text should fail on foregin element tags #11083
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
Changes from all commits
091d72b
7babedf
23c15f5
34925d5
3e88f34
c5ef32a
cfb6a53
893c28d
92a127b
dc65bb3
2b443a8
bfae594
768310e
dd8b09e
f35efcf
ae8da66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -644,7 +644,7 @@ public function test_json_auto_escaping() { | |
| * | ||
| * @ticket 64609 | ||
| */ | ||
| public function test_modifiable_text_special_textarea() { | ||
| public function test_modifiable_text_special_textarea(): void { | ||
| $processor = new WP_HTML_Tag_Processor( '<textarea></textarea>' ); | ||
| $processor->next_token(); | ||
| $processor->set_modifiable_text( "\nAFTER NEWLINE" ); | ||
|
|
@@ -664,4 +664,60 @@ public function test_modifiable_text_special_textarea() { | |
| 'Should have preserved the leading newline in the content.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that `set_modifiable_text()` returns false for elements that are | ||
| * not special "atomic" elements. | ||
| * | ||
| * This includes atomic-like foreign elements as well as non-atomic foreign elements. | ||
| * | ||
| * @ticket 64751 | ||
| * @dataProvider data_set_modifiable_fails_non_atomic_tags | ||
| */ | ||
| public function test_set_modifiable_fails_non_atomic_tags( | ||
| string $html, | ||
| string $parsing_namespace, | ||
| string $target_tag | ||
| ): void { | ||
| $processor = new WP_HTML_Tag_Processor( $html ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is ultimately a test of the Tag Processor and its behavior, no? as in, a failure here is a bug, but a failure in the HTML Processor is a bug in detecting namespace changes. Does it make sense to run the test in both places? If so, wouldn’t it be quite easy for the tests to diverge given that they are in separate files? If we want to ensure that the behavior is locked, why not run both classes from this same test runner? Since we have tests already asserting that the HTML Processor detects the namespace changes, we should only need to test the modifiable text behavior here, and therefore we should be fine reading the namespace from the HTML Processor rather than supplying it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what you have in mind here, perhaps you could clarify. I'm open to changing or moving things, there is some duplication between these tests. I will elaborate that the HTML Processor tests have added value. Subtle issues can appear in the interaction between the "smart" HTML processor and the "syntax-only" tag processor. For example, this change appears equivalent, but it would make the HTML processor tests fail, detecting an issue with diff --git c/src/wp-includes/html-api/class-wp-html-tag-processor.php i/src/wp-includes/html-api/class-wp-html-tag-processor.php
index d544f0f49b..cba78fdb51 100644
--- c/src/wp-includes/html-api/class-wp-html-tag-processor.php
+++ i/src/wp-includes/html-api/class-wp-html-tag-processor.php
@@ -3813,7 +3813,7 @@ class WP_HTML_Tag_Processor {
*/
if (
self::STATE_MATCHED_TAG !== $this->parser_state ||
- 'html' !== $this->get_namespace()
+ 'html' !== $this->parsing_namespace
) {
return false;
}That's because
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, but wouldn’t or shouldn’t this test case be caught by those tests covering the integration point logic, and not slipped under the rug in a seemingly unrelated test? on the contrary, if we introduced this bug, I would want that to cause a failure in detecting the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bug in the diff I shared would be in the implementation of the I'm not sure how else that particular issue could be detected. It's not a problem in any of the other systems. It would be a bug with |
||
| $processor->change_parsing_namespace( $parsing_namespace ); | ||
| $this->assertTrue( $processor->next_tag( $target_tag ), 'Failed to find target tag.' ); | ||
| $this->assertFalse( | ||
| $processor->set_modifiable_text( 'test' ), | ||
| "set_modifiable_text() should return false for {$parsing_namespace}:{$target_tag}." | ||
| ); | ||
| $this->assertSame( | ||
| $html, | ||
| $processor->get_updated_html(), | ||
| 'HTML should be unchanged after rejected set_modifiable_text().' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array<string, array{0: string, 1: string, 2: string}> | ||
| */ | ||
| public static function data_set_modifiable_fails_non_atomic_tags(): array { | ||
| return array( | ||
| // Plain HTML tags. | ||
| 'html DIV' => array( '<div>', 'html', 'DIV' ), | ||
|
|
||
| // Foreign elements with non-atomic tags. | ||
| 'svg PATH' => array( '<path></path>', 'svg', 'PATH' ), | ||
| 'svg PATH (self-closing)' => array( '<path />', 'svg', 'PATH' ), | ||
| 'math MTEXT' => array( '<mtext></mtext>', 'math', 'MTEXT' ), | ||
| 'math MSPACE (self-closing)' => array( '<mspace />', 'math', 'MSPACE' ), | ||
|
|
||
| // Foreign elements with atomic-like tags. | ||
| 'svg TEXTAREA' => array( '<textarea></textarea>', 'svg', 'TEXTAREA' ), | ||
| 'svg TITLE' => array( '<title></title>', 'svg', 'TITLE' ), | ||
| 'svg STYLE' => array( '<style></style>', 'svg', 'STYLE' ), | ||
| 'svg SCRIPT' => array( '<script></script>', 'svg', 'SCRIPT' ), | ||
| 'math TEXTAREA' => array( '<textarea></textarea>', 'math', 'TEXTAREA' ), | ||
| 'math TITLE' => array( '<title></title>', 'math', 'TITLE' ), | ||
| 'math STYLE' => array( '<style></style>', 'math', 'STYLE' ), | ||
| 'math SCRIPT' => array( '<script></script>', 'math', 'SCRIPT' ), | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.