Skip to content

Commit 1142f8f

Browse files
westonruterdmsnell
andcommitted
Improve parsing of media type
Co-authored-by: Dennis Snell <[email protected]>
1 parent ba1626a commit 1142f8f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/wp-includes/template.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,19 @@ function wp_finalize_template_enhancement_output_buffer( string $output, int $ph
931931
count( $header_parts ) === 2 &&
932932
'content-type' === $header_parts[0]
933933
) {
934-
$content_type = trim( strtok( $header_parts[1], ';' ) );
935-
$is_html_content_type = in_array( $content_type, $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 );
936947
break; // PHP only sends the first Content-Type header in the list.
937948
}
938949
}

0 commit comments

Comments
 (0)