-
Notifications
You must be signed in to change notification settings - Fork 3.6k
HTML API: Preserve raw text in serialize, allow setting #12289
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
81b255d
2f02318
1589a14
6631b20
7712560
d99da28
e57bb40
d2c76f6
1018e33
0c7fad1
7a5300d
f9defb1
0116aa0
3dd84bf
edb2273
aa088e1
14f2d88
89bc631
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 |
|---|---|---|
|
|
@@ -270,22 +270,6 @@ public function test_style_contents_are_not_escaped() { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * XMP contents are parsed using the generic raw text element parsing algorithm. | ||
| * Their contents should not be escaped with HTML character references on normalization. | ||
| * | ||
| * @ticket 65372 | ||
| */ | ||
| public function test_xmp_contents_are_not_escaped() { | ||
| $normalized = WP_HTML_Processor::normalize( "<xmp> < > & \" ' \x00 </xmp>" ); | ||
|
|
||
| $this->assertSame( | ||
| "<xmp> < > & \" ' \u{FFFD} </xmp>", | ||
| $normalized, | ||
| 'Should have preserved text inside an XMP element, except for replacing NULL bytes.' | ||
| ); | ||
| } | ||
|
|
||
| public function test_unexpected_closing_tags_are_removed() { | ||
| $this->assertSame( | ||
| WP_HTML_Processor::normalize( 'one</div>two</span>three' ), | ||
|
|
@@ -481,9 +465,9 @@ public function test_replaces_null_bytes_appropriately( string $html_with_nulls, | |
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array[] | ||
| * @return array<string, array{string, string}> | ||
| */ | ||
| public static function data_tokens_with_null_bytes() { | ||
| public static function data_tokens_with_null_bytes(): array { | ||
| return array( | ||
| 'Tag name' => array( "<img\x00id=5>", "<img\u{FFFD}id=5></img\u{FFFD}id=5>" ), | ||
| 'Attribute name' => array( "<img/\x00id=5>", "<img \u{FFFD}id=\"5\">" ), | ||
|
|
@@ -492,11 +476,45 @@ public static function data_tokens_with_null_bytes() { | |
| 'Foreign content text' => array( "<svg>one\x00two</svg>", "<svg>one\u{FFFD}two</svg>" ), | ||
| 'SCRIPT content' => array( "<script>alert(\x00)</script>", "<script>alert(\u{FFFD})</script>" ), | ||
| 'STYLE content' => array( "<style>\x00 {}</style>", "<style>\u{FFFD} {}</style>" ), | ||
| 'IFRAME content' => array( "<iframe>a\x00b</iframe>", "<iframe>a\u{FFFD}b</iframe>" ), | ||
| 'NOEMBED content' => array( "<noembed>a\x00b</noembed>", "<noembed>a\u{FFFD}b</noembed>" ), | ||
| 'NOFRAMES content' => array( "<noframes>a\x00b</noframes>", "<noframes>a\u{FFFD}b</noframes>" ), | ||
|
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. we don’t currently allow setting modifiable text in these, so it may be appropriate to toggle that in this same change, and follow what we do with SCRIPT and TITLE etc... and start rejecting updates which otherwise would contain closing tags for these. although they are special atomic elements, we can find isolated closing tags. to make it easier we could reject strings containing
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. Addressed in 7a5300d by enabling Verified with PHPCS, the focused modifiable-text tests, the HTML Processor serialization class, and the full |
||
| 'XMP content' => array( "<xmp>a\x00b</xmp>", "<xmp>a\u{FFFD}b</xmp>" ), | ||
| 'Comment text' => array( "<!-- \x00 -->", "<!-- \u{FFFD} -->" ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that contents of rawtext elements are preserved when serializing. | ||
| * | ||
| * @ticket 65372 | ||
| * | ||
| * @dataProvider data_rawtext_elements_with_html_syntax_character_contents | ||
| * | ||
| * @param string $html Normalized HTML containing a rawtext element with contents. | ||
| */ | ||
| public function test_rawtext_element_contents_are_preserved_when_normalizing( string $html ): void { | ||
| $this->assertSame( | ||
| $html, | ||
| WP_HTML_Processor::normalize( $html ), | ||
| 'Should have preserved the rawtext element contents.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array<string, array{string}> | ||
| */ | ||
| public static function data_rawtext_elements_with_html_syntax_character_contents(): array { | ||
| return array( | ||
| 'IFRAME' => array( 'before<iframe> < > & " \' </iframe>after' ), | ||
| 'NOEMBED' => array( 'before<noembed> < > & " \' </noembed>after' ), | ||
| 'NOFRAMES' => array( 'before<noframes> < > & " \' </noframes>after' ), | ||
| 'XMP' => array( 'before<xmp> < > & " \' </xmp>after' ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 62396 | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.