-
Notifications
You must be signed in to change notification settings - Fork 3.3k
HTML API: Simplify META tag encoding processing #9231
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
Closed
sirreal
wants to merge
5
commits into
WordPress:trunk
from
sirreal:html-api/simplify-meta-tag-encoding-handling
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <?php | ||
| /** | ||
| * Unit tests covering WP_HTML_Processor META tag handling. | ||
| * | ||
| * @package WordPress | ||
| * @subpackage HTML-API | ||
| * | ||
| * @since 6.9 | ||
| * | ||
| * @group html-api | ||
| * | ||
| * @coversDefaultClass WP_HTML_Processor | ||
| */ | ||
| class Tests_HtmlApi_WpHtmlProcessorMetaTag extends WP_UnitTestCase { | ||
| /** | ||
| * Data provider. | ||
| */ | ||
| public static function data_supported_meta_tags(): array { | ||
| return array( | ||
| 'No attributes' => array( '<meta>' ), | ||
| 'Unrelated attributes' => array( '<meta not-charset="OK">' ), | ||
| 'Boolean charset' => array( '<meta charset>' ), | ||
| 'HTTP Equiv: accept' => array( '<meta http-equiv="accept" content="">' ), | ||
| 'HTTP Equiv: content-type, no content' => array( '<meta http-equiv="content-type">' ), | ||
| 'Boolean HTTP Equiv' => array( '<meta http-equiv content="">' ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that META tags correctly handle encoding confidence. | ||
| * | ||
| * @ticket 63738 | ||
| * | ||
| * @dataProvider data_supported_meta_tags | ||
| */ | ||
| public function test_supported_meta_tag( string $html ) { | ||
| $html = '<!DOCTYPE html>' . $html; | ||
| $processor = new class($html) extends WP_HTML_Processor { | ||
| public function __construct( $html ) { | ||
| parent::__construct( $html, parent::CONSTRUCTOR_UNLOCK_CODE ); | ||
| } | ||
| }; | ||
|
|
||
| $this->assertTrue( $processor->next_tag( 'META' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| */ | ||
| public function data_unsupported_meta_tags(): array { | ||
sirreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return array( | ||
| 'With charset' => array( '<meta charset="utf8">', 'Cannot yet process META tags with charset to determine encoding.' ), | ||
| 'With CHARSET' => array( '<meta CHARSET="utf8">', 'Cannot yet process META tags with charset to determine encoding.' ), | ||
| 'With http-equiv' => array( '<meta http-equiv="content-type" content="">', 'Cannot yet process META tags with http-equiv Content-Type to determine encoding.' ), | ||
| 'With http-equiv and content' => array( '<meta http-equiv="Content-Type" content="UTF-8">', 'Cannot yet process META tags with http-equiv Content-Type to determine encoding.' ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that unsupported encoding META tags bail. | ||
| * | ||
| * @ticket 63738 | ||
| * | ||
| * @dataProvider data_unsupported_meta_tags | ||
| */ | ||
| public function test_unsupported_meta_tags( string $html, string $unsupported_message ) { | ||
| $html = '<!DOCTYPE html>' . $html; | ||
| $processor = new class($html) extends WP_HTML_Processor { | ||
| public function __construct( $html ) { | ||
| parent::__construct( $html, parent::CONSTRUCTOR_UNLOCK_CODE ); | ||
| } | ||
| }; | ||
|
|
||
| $this->assertFalse( $processor->next_tag( 'META' ) ); | ||
| $this->assertInstanceOf( WP_HTML_Unsupported_Exception::class, $processor->get_unsupported_exception() ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.