Coding Standards: Use strict type check for `in_array()` in `wp-includes/feed.php`.

Additionally:
* Correct inline comments per the documentation standards.
* Correct the `@ticket` reference in `tests/feed/atom.php`.

Follow-up to [48429].

See #33591.

git-svn-id: https://develop.svn.wordpress.org/trunk@48435 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-07-11 12:12:46 +00:00
parent 8dc7f1c348
commit b4232b7de7
2 changed files with 16 additions and 10 deletions

View File

@ -526,17 +526,17 @@ function atom_enclosure() {
$mimes = get_allowed_mime_types();
// Parse url
// Parse URL.
if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) {
$url = trim( $enclosure[0] );
}
// Parse length and type
foreach ( range( 1, 2 ) as $i ) {
// Parse length and type.
for ( $i = 1; $i <= 2; $i++ ) {
if ( isset( $enclosure[ $i ] ) ) {
if ( is_numeric( $enclosure[ $i ] ) ) {
$length = trim( $enclosure[ $i ] );
} elseif ( in_array( $enclosure[ $i ], $mimes ) ) {
} elseif ( in_array( $enclosure[ $i ], $mimes, true ) ) {
$type = trim( $enclosure[ $i ] );
}
}
@ -548,6 +548,7 @@ function atom_enclosure() {
esc_attr( $length ),
esc_attr( $type )
);
/**
* Filters the atom enclosure HTML link tag for the current post.
*

View File

@ -207,12 +207,13 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
}
/**
* @test 33591
* @ticket 33591
*/
function test_atom_enclosure_with_extended_url_length_type_parsing() {
$enclosures = array(
array(
'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", // url length type
// URL, length, type.
'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4",
'expected' => array(
'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4',
'length' => 318465,
@ -220,7 +221,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
),
),
array(
'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\nvideo/mp4\n318465", // url type length
// URL, type, length.
'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\nvideo/mp4\n318465",
'expected' => array(
'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4',
'length' => 318465,
@ -228,7 +230,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
),
),
array(
'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465", // url length
// URL, length.
'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465",
'expected' => array(
'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4',
'length' => 318465,
@ -236,7 +239,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
),
),
array(
'actual' => "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n\naudio/mpeg", // url type
// URL, type.
'actual' => "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n\naudio/mpeg",
'expected' => array(
'href' => 'https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3',
'length' => 0,
@ -244,7 +248,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
),
),
array(
'actual' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4', // url
// URL.
'actual' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4',
'expected' => array(
'href' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4',
'length' => 0,