From 6fa3286a1b26bd5063efba30c1254ccdaae38d6c Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 26 Jul 2020 14:06:03 +0000 Subject: [PATCH] Pings/Trackbacks: Avoid a PHP notice in `do_enclose()` when encountering a URL without a path in post content. Props jbouganim, mukesh27, Otto42, SergeyBiryukov. Fixes #49872. git-svn-id: https://develop.svn.wordpress.org/trunk@48621 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 2 +- tests/phpunit/tests/functions/doEnclose.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 7127f145cc..b07ecb7f4d 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -907,7 +907,7 @@ function do_enclose( $content = null, $post ) { // Check to see if we can figure out the mime type from the extension. $url_parts = parse_url( $url ); - if ( false !== $url_parts ) { + if ( false !== $url_parts && ! empty( $url_parts['path'] ) ) { $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); if ( ! empty( $extension ) ) { foreach ( wp_get_mime_types() as $exts => $mime ) { diff --git a/tests/phpunit/tests/functions/doEnclose.php b/tests/phpunit/tests/functions/doEnclose.php index 8b38e9f574..c994ea360c 100644 --- a/tests/phpunit/tests/functions/doEnclose.php +++ b/tests/phpunit/tests/functions/doEnclose.php @@ -135,6 +135,10 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { 'expected' => "https://example.com/wp-content/uploads/2018/06/audio.ogg\n321\naudio/ogg\n" . "https://example.com/wp-content/uploads/2018/06/movie.mp4\n123\nvideo/mp4\n", ), + 'no-path' => array( + 'content' => 'https://example.com?test=1', + 'expected' => '', + ), ); }