Skip to content

Commit 501d201

Browse files
committed
Clean up and improve type/language logic
1 parent f8cfdf9 commit 501d201

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,16 +3967,12 @@ public function is_javascript_script_tag(): bool {
39673967
*/
39683968
$type_attr = $this->get_attribute( 'type' );
39693969
$language_attr = $this->get_attribute( 'language' );
3970-
39713970
if ( true === $type_attr || '' === $type_attr ) {
39723971
return true;
39733972
}
39743973
if (
3975-
null === $type_attr && (
3976-
true === $language_attr ||
3977-
'' === $language_attr ||
3978-
null === $language_attr
3979-
)
3974+
null === $type_attr
3975+
&& ( null === $language_attr || true === $language_attr || '' === $language_attr )
39803976
) {
39813977
return true;
39823978
}
@@ -3987,7 +3983,7 @@ public function is_javascript_script_tag(): bool {
39873983
* > Otherwise, el has a non-empty language attribute; let the script block's type string
39883984
* > be the concatenation of "text/" and the value of el's language attribute.
39893985
*/
3990-
$type_string = $type_attr ? trim( $type_attr, " \t\f\r\n" ) : "text/{$language_attr}";
3986+
$type_string = null !== $type_attr ? trim( $type_attr, " \t\f\r\n" ) : "text/{$language_attr}";
39913987

39923988
/*
39933989
* > If the script block's type string is a JavaScript MIME type essence match, then
@@ -4048,10 +4044,10 @@ public function is_javascript_script_tag(): bool {
40484044
}
40494045

40504046
/*
4051-
* > - Otherwise, if the script block's type string is an ASCII case-insensitive match for
4052-
* > the string "importmap", then set el's type to "importmap".
4047+
* > Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "importmap", then set el's type to "importmap".
4048+
* > Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "speculationrules", then set el's type to "speculationrules".
40534049
*
4054-
* An importmap is JSON and not evaluated as JavaScript. This case is not handled here.
4050+
* These conditions indicate JSON content.
40554051
*/
40564052

40574053
/*
@@ -4072,13 +4068,11 @@ public function is_json_script_tag(): bool {
40724068
return false;
40734069
}
40744070

4075-
$type_attr = $this->get_attribute( 'type' );
4076-
4077-
if ( empty( $type_attr ) || true === $type_attr ) {
4071+
$type = $this->get_attribute( 'type' );
4072+
if ( null === $type || true === $type || '' === $type ) {
40784073
return false;
40794074
}
4080-
4081-
$type_string = strtolower( trim( $type_attr, " \t\f\r\n" ) );
4075+
$type = strtolower( trim( $type, " \t\f\r\n" ) );
40824076

40834077
/*
40844078
* > …
@@ -4095,10 +4089,10 @@ public function is_json_script_tag(): bool {
40954089
* @see https://mimesniff.spec.whatwg.org/#json-mime-type
40964090
*/
40974091
if (
4098-
'application/json' === $type_string
4099-
|| 'importmap' === $type_string
4100-
|| 'speculationrules' === $type_string
4101-
|| 'text/json' === $type_string
4092+
'application/json' === $type
4093+
|| 'importmap' === $type
4094+
|| 'speculationrules' === $type
4095+
|| 'text/json' === $type
41024096
) {
41034097
return true;
41044098
}

0 commit comments

Comments
 (0)