Changeset 58925
- Timestamp:
- 08/23/2024 02:53:59 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpcs.xml.dist
r58107 r58925 263 263 <rule ref="Generic.PHP.DiscourageGoto.Found"> 264 264 <exclude-pattern>/wp-includes/html-api/class-wp-html-processor\.php</exclude-pattern> 265 <exclude-pattern>/wp-includes/html-api/class-wp-html-doctype-info\.php</exclude-pattern> 265 266 </rule> 266 267 -
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r58898 r58925 1077 1077 */ 1078 1078 case 'html': 1079 $contents = $this->get_modifiable_text(); 1080 if ( ' html' !== $contents ) { 1081 /* 1082 * @todo When the HTML Tag Processor fully parses the DOCTYPE declaration, 1083 * this code should examine the contents to set the compatability mode. 1084 */ 1085 $this->bail( 'Cannot process any DOCTYPE other than a normative HTML5 doctype.' ); 1079 $doctype = $this->get_doctype_info(); 1080 if ( null !== $doctype && 'quirks' === $doctype->indicated_compatability_mode ) { 1081 $this->state->document_mode = WP_HTML_Processor_State::QUIRKS_MODE; 1086 1082 } 1087 1083 … … 1090 1086 */ 1091 1087 $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HTML; 1088 $this->insert_html_element( $this->state->current_token ); 1092 1089 return true; 1093 1090 } … … 1097 1094 */ 1098 1095 initial_anything_else: 1096 $this->state->document_mode = WP_HTML_Processor_State::QUIRKS_MODE; 1099 1097 $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HTML; 1100 1098 return $this->step( self::REPROCESS_CURRENT_NODE ); -
trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php
r58897 r58925 4028 4028 4029 4029 /** 4030 * Gets DOCTYPE declaration info from a DOCTYPE token. 4031 * 4032 * DOCTYPE tokens may appear in many places in an HTML document. In most places, they are 4033 * simply ignored. The main parsing functions find the basic shape of DOCTYPE tokens but 4034 * do not perform detailed parsing. 4035 * 4036 * This method can be called to perform a full parse of the DOCTYPE token and retrieve 4037 * its information. 4038 * 4039 * @return WP_HTML_Doctype_Info|null The DOCTYPE declaration information or `null` if not 4040 * currently at a DOCTYPE node. 4041 */ 4042 public function get_doctype_info(): ?WP_HTML_Doctype_Info { 4043 if ( self::STATE_DOCTYPE !== $this->parser_state ) { 4044 return null; 4045 } 4046 4047 return WP_HTML_Doctype_Info::from_doctype_token( substr( $this->html, $this->token_starts_at, $this->token_length ) ); 4048 } 4049 4050 /** 4030 4051 * Parser Ready State. 4031 4052 * … … 4118 4139 /** 4119 4140 * Indicates that the parser has found a DOCTYPE node and it's 4120 * possible to read and modify its modifiable text.4141 * possible to read its DOCTYPE information via `get_doctype_info()`. 4121 4142 * 4122 4143 * @since 6.5.0 -
trunk/src/wp-settings.php
r58672 r58925 253 253 require ABSPATH . WPINC . '/html-api/class-wp-html-attribute-token.php'; 254 254 require ABSPATH . WPINC . '/html-api/class-wp-html-span.php'; 255 require ABSPATH . WPINC . '/html-api/class-wp-html-doctype-info.php'; 255 256 require ABSPATH . WPINC . '/html-api/class-wp-html-text-replacement.php'; 256 257 require ABSPATH . WPINC . '/html-api/class-wp-html-decoder.php'; -
trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
r58870 r58925 28 28 'comments01/line0155' => 'Unimplemented: Need to access raw comment text on non-normative comments.', 29 29 'comments01/line0169' => 'Unimplemented: Need to access raw comment text on non-normative comments.', 30 'doctype01/line0380' => 'Bug: Mixed whitespace, non-whitespace text in head not split correctly', 30 31 'html5test-com/line0129' => 'Unimplemented: Need to access raw comment text on non-normative comments.', 31 32 'noscript01/line0014' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.', … … 116 117 $test_context_element = $test[1]; 117 118 118 if ( self::should_skip_test( $test_context_element, $test_name , $test[3]) ) {119 if ( self::should_skip_test( $test_context_element, $test_name ) ) { 119 120 continue; 120 121 } … … 134 135 * @return bool True if the test case should be skipped. False otherwise. 135 136 */ 136 private static function should_skip_test( ?string $test_context_element, string $test_name , string $expected_tree): bool {137 private static function should_skip_test( ?string $test_context_element, string $test_name ): bool { 137 138 if ( null !== $test_context_element && 'body' !== $test_context_element ) { 138 139 return true; … … 190 191 191 192 switch ( $token_type ) { 193 case '#doctype': 194 $doctype = $processor->get_doctype_info(); 195 $output .= "<!DOCTYPE {$doctype->name}"; 196 if ( null !== $doctype->public_identifier || null !== $doctype->system_identifier ) { 197 $output .= " \"{$doctype->public_identifier}\" \"{$doctype->system_identifier}\""; 198 } 199 $output .= ">\n"; 200 break; 201 192 202 case '#tag': 193 203 $namespace = $processor->get_namespace(); … … 451 461 case 'document': 452 462 if ( '|' === $line[0] ) { 453 /* 454 * The next_token() method these tests rely on do not stop 455 * at doctype nodes. Strip doctypes from output. 456 * @todo Restore this line if and when the processor 457 * exposes doctypes. 458 */ 459 if ( '| <!DOCTYPE ' !== substr( $line, 0, 12 ) ) { 460 $test_dom .= substr( $line, 2 ); 461 } 463 $test_dom .= substr( $line, 2 ); 462 464 } else { 463 465 // This is a text node that includes unescaped newlines. -
trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php
r58893 r58925 2940 2940 $this->assertTrue( $processor->paused_at_incomplete_token() ); 2941 2941 } 2942 2943 /** 2944 * Test basic DOCTYPE handling. 2945 * 2946 * @ticket 61576 2947 */ 2948 public function test_doctype_doc_name() { 2949 $processor = new WP_HTML_Tag_Processor( '<!DOCTYPE html>' ); 2950 $this->assertTrue( $processor->next_token() ); 2951 $doctype = $processor->get_doctype_info(); 2952 $this->assertNotNull( $doctype ); 2953 $this->assertSame( 'html', $doctype->name ); 2954 $this->assertSame( 'no-quirks', $doctype->indicated_compatability_mode ); 2955 $this->assertNull( $doctype->public_identifier ); 2956 $this->assertNull( $doctype->system_identifier ); 2957 } 2942 2958 }
Note: See TracChangeset
for help on using the changeset viewer.