diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index c19daed695..a997280779 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -2943,6 +2943,10 @@ function _make_url_clickable_cb( $matches ) { $suffix = $matches[3]; } + if ( isset( $matches[4] ) && ! empty( $matches[4] ) ) { + $url .= $matches[4]; + } + // Include parentheses in the URL only if paired. while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) { $suffix = strrchr( $url, ')' ) . $suffix; @@ -3115,6 +3119,7 @@ function make_clickable( $text ) { )* ) (\)?) # 3: Trailing closing parenthesis (for parenthesis balancing post processing). + (\\.\\w{2,6})? # 4: Allowing file extensions (e.g., .jpg, .png). ~xS'; /* * The regex is a non-anchored pattern and does not have a single fixed starting character. diff --git a/tests/phpunit/tests/formatting/makeClickable.php b/tests/phpunit/tests/formatting/makeClickable.php index d06802afec..5e4c62a149 100644 --- a/tests/phpunit/tests/formatting/makeClickable.php +++ b/tests/phpunit/tests/formatting/makeClickable.php @@ -245,6 +245,16 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase { Richard Hamming wrote about people getting more done with their doors closed, but', ), + // @ticket #62037 + 'URL with brackets in path before the extension' => array( + 'text' => 'http://example-image(2).jpg', + 'expected' => 'http://example-image(2).jpg', + ), + 'URL with brackets within path and with a extension' => array( + 'text' => 'http://example-(2)-image.jpg', + 'expected' => 'http://example-(2)-image.jpg', + ), + // @ticket 11211 // Test with real comments which were incorrectly linked. 'real world: example.com text (.org URL)' => array(