Make WordPress Core

Changeset 59143


Ignore:
Timestamp:
09/30/2024 11:27:34 PM (9 months ago)
Author:
peterwilsoncc
Message:

Formatting: Improve parenthesis handling in make_clickable().

Improve the regular expression for making links clickable to account for parenthesis in links containing an extension, for example: http://wordpress.org/my-image(2).jpg.

Props coquardcyr, hellofromtonya, parthvataliya, rhellewellgmailcom.
Fixes #62037.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r59120 r59143  
    29442944    }
    29452945
     2946    if ( isset( $matches[4] ) && ! empty( $matches[4] ) ) {
     2947        $url .= $matches[4];
     2948    }
     2949
    29462950    // Include parentheses in the URL only if paired.
    29472951    while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
     
    31163120                )
    31173121                (\)?)                                          # 3: Trailing closing parenthesis (for parenthesis balancing post processing).
     3122                (\\.\\w{2,6})?                                 # 4: Allowing file extensions (e.g., .jpg, .png).
    31183123            ~xS';
    31193124            /*
  • trunk/tests/phpunit/tests/formatting/makeClickable.php

    r57987 r59143  
    246246            ),
    247247
     248            // @ticket #62037
     249            'URL with brackets in path before the extension' => array(
     250                'text'     => 'http://example-image(2).jpg',
     251                'expected' => '<a href="http://example-image(2).jpg" rel="nofollow">http://example-image(2).jpg</a>',
     252            ),
     253            'URL with brackets within path and with a extension' => array(
     254                'text'     => 'http://example-(2)-image.jpg',
     255                'expected' => '<a href="http://example-(2)-image.jpg" rel="nofollow">http://example-(2)-image.jpg</a>',
     256            ),
     257
    248258            // @ticket 11211
    249259            // Test with real comments which were incorrectly linked.
Note: See TracChangeset for help on using the changeset viewer.