-
Notifications
You must be signed in to change notification settings - Fork 3.2k
HTML API: Ensure correct encoding of modified class names #10591
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
2c8756b
cf42da8
135f3dd
99d7043
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 |
|---|---|---|
|
|
@@ -2887,11 +2887,11 @@ public static function data_updating_attributes_in_malformed_html() { | |
| ), | ||
| 'HTML tag opening inside attribute value' => array( | ||
| 'input' => '<pre id="<code" class="wp-block-code <code is poetry>"><code>This <is> a <strong is="true">thing.</code></pre><span>test</span>', | ||
| 'expected' => '<pre foo="bar" id="<code" class="wp-block-code <code is poetry&gt; firstTag"><code class="secondTag">This <is> a <strong is="true">thing.</code></pre><span>test</span>', | ||
| 'expected' => '<pre foo="bar" id="<code" class="wp-block-code <code is poetry> firstTag"><code class="secondTag">This <is> a <strong is="true">thing.</code></pre><span>test</span>', | ||
| ), | ||
| 'HTML tag brackets in attribute values and data markup' => array( | ||
| 'input' => '<pre id="<code->-block->" class="wp-block-code <code is poetry>"><code>This <is> a <strong is="true">thing.</code></pre><span>test</span>', | ||
| 'expected' => '<pre foo="bar" id="<code->-block->" class="wp-block-code <code is poetry&gt; firstTag"><code class="secondTag">This <is> a <strong is="true">thing.</code></pre><span>test</span>', | ||
| 'expected' => '<pre foo="bar" id="<code->-block->" class="wp-block-code <code is poetry> firstTag"><code class="secondTag">This <is> a <strong is="true">thing.</code></pre><span>test</span>', | ||
|
Comment on lines
+2890
to
+2894
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. These tests seem to have been ensuring incorrect behavior. In both cases updated here an input class like They were updated in #10143. This change restores their original (correct) assertion. |
||
| ), | ||
| 'Single and double quotes in attribute value' => array( | ||
| 'input' => '<p title="Demonstrating how to use single quote (\') and double quote (")"><span>test</span>', | ||
|
|
@@ -3028,6 +3028,50 @@ public static function data_updating_attributes_in_malformed_html() { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 64340 | ||
| */ | ||
| public function test_class_changes_produce_correct_html() { | ||
| $processor = new WP_HTML_Tag_Processor( '<div class="&">' ); | ||
| $processor->next_tag(); | ||
|
|
||
| $processor->add_class( '"' ); | ||
| $processor->get_updated_html(); | ||
|
|
||
| $processor->add_class( 'OK' ); | ||
| $processor->get_updated_html(); | ||
|
|
||
| $this->assertTrue( $processor->has_class( '&' ), 'Missing expected "&" class.' ); | ||
| $this->assertTrue( $processor->has_class( '"' ), 'Missing expected \'"\' class.' ); | ||
| $this->assertTrue( $processor->has_class( 'OK' ), 'Missing expected "OK" class.' ); | ||
|
|
||
| $expected = '<div class="& " OK">'; | ||
| $this->assertEqualHTML( | ||
| $expected, | ||
| $processor->get_updated_html(), | ||
| '<body>', | ||
| 'HTML was not correctly updated after adding classes.' | ||
| ); | ||
|
|
||
| $processor->remove_class( '&' ); | ||
| $processor->get_updated_html(); | ||
|
|
||
| $processor->remove_class( '"' ); | ||
| $processor->get_updated_html(); | ||
|
|
||
| $this->assertFalse( $processor->has_class( '&' ) ); | ||
| $this->assertFalse( $processor->has_class( '"' ) ); | ||
| $this->assertTrue( $processor->has_class( 'OK' ) ); | ||
|
|
||
| $expected = '<div class="OK">'; | ||
| $this->assertEqualHTML( | ||
| $expected, | ||
| $processor->get_updated_html(), | ||
| '<body>', | ||
| 'HTML was not correctly updated after removing classes.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers WP_HTML_Tag_Processor::next_tag | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve been staring at this for a bit now and have no idea how we missed it. Surely we didn’t overlook this since 6.2 in the original introduction?
but you know what? we did!
now I don’t remember why; maybe it was performance-related or maybe it was a choice to lean on already-existing bugs, but I suppose it’s proper here to fix it regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there's been a latent issue for a while that was covered up by the behavior of
esc_html(). It's become very clear with the change in 6.9 to use more rigorous attribute encoding.