Changeset 60973
- Timestamp:
- 10/19/2025 12:19:27 AM (12 hours ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/template.php
r60944 r60973 927 927 $html_content_types = array( 'text/html', 'application/xhtml+xml' ); 928 928 foreach ( headers_list() as $header ) { 929 $header_parts = preg_split( '/\s*[:;]\s*/', strtolower( $header ));929 $header_parts = explode( ':', strtolower( $header ), 2 ); 930 930 if ( 931 is_array( $header_parts ) && 932 count( $header_parts ) >= 2 && 931 count( $header_parts ) === 2 && 933 932 'content-type' === $header_parts[0] 934 933 ) { 935 $is_html_content_type = in_array( $header_parts[1], $html_content_types, true ); 934 /* 935 * This is looking for very specific content types, therefore it 936 * doesn’t need to fully parse the header’s value. Instead, it needs 937 * only assert that the content type is one of the static HTML types. 938 * 939 * Example: 940 * 941 * Content-Type: text/html; charset=utf8 942 * Content-Type: text/html ;charset=latin4 943 * Content-Type:application/xhtml+xml 944 */ 945 $media_type = trim( strtok( $header_parts[1], ';' ), " \t" ); 946 $is_html_content_type = in_array( $media_type, $html_content_types, true ); 936 947 break; // PHP only sends the first Content-Type header in the list. 937 948 } -
trunk/tests/phpunit/tests/template.php
r60945 r60973 598 598 ); 599 599 600 $this->assertCount( 0, headers_list(), 'Expected no headers to have been sent during unit tests.' ); 601 ini_set( 'default_mimetype', 'text/html' ); // Since sending a header won't work. 602 600 603 $initial_ob_level = ob_get_level(); 601 604 $this->assertTrue( wp_start_template_enhancement_output_buffer(), 'Expected wp_start_template_enhancement_output_buffer() to return true indicating the output buffer started.' ); … … 676 679 } 677 680 ); 681 682 $this->assertCount( 0, headers_list(), 'Expected no headers to have been sent during unit tests.' ); 683 ini_set( 'default_mimetype', 'text/html' ); // Since sending a header won't work. 678 684 679 685 $initial_ob_level = ob_get_level(); … … 741 747 ); 742 748 749 $this->assertCount( 0, headers_list(), 'Expected no headers to have been sent during unit tests.' ); 750 ini_set( 'default_mimetype', 'application/xhtml+xml' ); // Since sending a header won't work. 751 743 752 $initial_ob_level = ob_get_level(); 744 753 $this->assertTrue( wp_start_template_enhancement_output_buffer(), 'Expected wp_start_template_enhancement_output_buffer() to return true indicating the output buffer started.' ); … … 750 759 <html lang="en"> 751 760 <head> 761 <meta charset="utf-8"> 752 762 <title>Unprocessed</title> 753 763 </head> … … 756 766 <!-- ... --> 757 767 <?php ob_clean(); // Clean the buffer started by wp_start_template_enhancement_output_buffer(), allowing the following document to replace the above.. ?> 768 <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> 758 769 <!DOCTYPE html> 759 <html lang="en">770 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 760 771 <head> 772 <meta charset="utf-8" /> 761 773 <title>Template Replaced</title> 762 774 </head> … … 800 812 $this->assertSame( $initial_ob_level + 1, ob_get_level(), 'Expected the output buffer level to have been incremented.' ); 801 813 814 $this->assertCount( 0, headers_list(), 'Expected no headers to have been sent during unit tests.' ); 802 815 ini_set( 'default_mimetype', 'application/json' ); // Since sending a header won't work. 816 803 817 $json = wp_json_encode( 804 818 array(
Note: See TracChangeset
for help on using the changeset viewer.