Skip to content

Commit 65bc8f0

Browse files
committed
Account for strtok() consuming initial commas
1 parent 0ad8338 commit 65bc8f0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

plugins/auto-sizes/hooks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ function auto_sizes_apply_tag_parser_updates( WP_HTML_Tag_Processor $processor )
116116
* @return bool True if the 'auto' keyword is present, false otherwise.
117117
*/
118118
function auto_sizes_attribute_includes_valid_auto( string $sizes_attr ): bool {
119-
$token = strtok( strtolower( $sizes_attr ), ',' );
120-
return false !== $token && 'auto' === trim( $token, " \t\f\r\n" );
119+
list( $first_size ) = explode( ',', $sizes_attr, 2 );
120+
return 'auto' === strtolower( trim( $first_size, " \t\f\r\n" ) );
121121
}
122122

123123
/**

plugins/auto-sizes/tests/test-auto-sizes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ public function data_provider_to_test_auto_sizes_update_content_img_tag(): array
266266
'input' => '<img src="https://example.com/foo-300x225.jpg" srcset="https://example.com/foo-300x225.jpg 300w, https://example.com/foo-1024x768.jpg 1024w, https://example.com/foo-768x576.jpg 768w, https://example.com/foo-1536x1152.jpg 1536w, https://example.com/foo-2048x1536.jpg 2048w" sizes="auto, (max-width: 650px) 100vw, 650px" loading="eager">',
267267
'expected' => '<img src="https://example.com/foo-300x225.jpg" srcset="https://example.com/foo-300x225.jpg 300w, https://example.com/foo-1024x768.jpg 1024w, https://example.com/foo-768x576.jpg 768w, https://example.com/foo-1536x1152.jpg 1536w, https://example.com/foo-2048x1536.jpg 2048w" sizes="(max-width: 650px) 100vw, 650px" loading="eager">',
268268
),
269+
'expected_when_auto_size_preceded_by_extra_commas' => array(
270+
'input' => '<img src="https://example.com/foo-300x225.jpg" srcset="https://example.com/foo-300x225.jpg 300w, https://example.com/foo-1024x768.jpg 1024w, https://example.com/foo-768x576.jpg 768w, https://example.com/foo-1536x1152.jpg 1536w, https://example.com/foo-2048x1536.jpg 2048w" sizes=",,,,,,,,,auto, (max-width: 650px) 100vw, 650px" loading="lazy">',
271+
'expected' => '<img src="https://example.com/foo-300x225.jpg" srcset="https://example.com/foo-300x225.jpg 300w, https://example.com/foo-1024x768.jpg 1024w, https://example.com/foo-768x576.jpg 768w, https://example.com/foo-1536x1152.jpg 1536w, https://example.com/foo-2048x1536.jpg 2048w" sizes="auto, ,,,,,,,,,auto, (max-width: 650px) 100vw, 650px" loading="lazy">',
272+
),
269273
);
270274
}
271275

0 commit comments

Comments
 (0)