Make WordPress Core

Ticket #23308: 23308.diff

File 23308.diff, 3.3 KB (added by mdawaffe, 12 years ago)
  • src/wp-includes/formatting.php

     
    16631663                $url = substr( $url, 0, strrpos( $url, ')' ) );
    16641664        }
    16651665
    1666         $url = esc_url($url);
     1666        // After removing the unmatched parentheses suffix,
     1667        // we need to re-ensure the URL does not end with punctuation.
     1668        $trimmed_url = rtrim( $url, "'.,;:!?" ); // taken from the list of punctuation characters in make_clickable()
     1669        $suffix = substr( $url, strlen( $trimmed_url ) ) . $suffix;
     1670
     1671        $url = esc_url($trimmed_url);
    16671672        if ( empty($url) )
    16681673                return $matches[0];
    16691674
    … …  
    17611766                                        [\\w]{1,20}+://                                # Scheme and hier-part prefix
    17621767                                        (?=\S{1,2000}\s)                               # Limit to URLs less than about 2000 characters long
    17631768                                        [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+         # Non-punctuation URL character
    1764                                         (?:                                            # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character
    1765                                                 [\'.,;:!?)]                            # Punctuation URL character
     1769                                        (?:                                            # Unroll the Loop: Only allow puctuation URL characters if followed by a non-punctuation URL character
     1770                                                [\'.,;:!?)]+                           # Punctuation URL character
    17661771                                                [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character
    17671772                                        )*
    17681773                                )
  • tests/phpunit/tests/formatting/MakeClickable.php

     
    389389                                  href='mailto:someone@example.com'>someone@example.com</a>";
    390390                $this->assertEquals( $html, make_clickable( $html ) );
    391391        }
     392
     393        /**
     394         * @ticket 23308
     395         */
     396        function test_parentheses_with_trailing_extension() {
     397                $urls_before = array(
     398                        'http://www.wordpress.org/some-(parentheses).html',
     399                        'foo http://www.wordpress.org/some-(parentheses).html bar',
     400                );
     401                $urls_expected = array(
     402                        '<a href="http://www.wordpress.org/some-(parentheses).html" rel="nofollow">http://www.wordpress.org/some-(parentheses).html</a>',
     403                        'foo <a href="http://www.wordpress.org/some-(parentheses).html" rel="nofollow">http://www.wordpress.org/some-(parentheses).html</a> bar',
     404                );
     405                foreach ($urls_before as $key => $url) {
     406                        $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
     407                }
     408        }
     409
     410        /**
     411         * @ticket 23308
     412         */
     413        function test_github_range_urls() {
     414                $urls_before = array(
     415                        'https://github.com/WordPress/WordPress/compare/3.9...3.9.1',
     416                        'foo https://github.com/WordPress/WordPress/compare/3.9...3.9.1 bar',
     417                );
     418                $urls_expected = array(
     419                        '<a href="https://github.com/WordPress/WordPress/compare/3.9...3.9.1" rel="nofollow">https://github.com/WordPress/WordPress/compare/3.9...3.9.1</a>',
     420                        'foo <a href="https://github.com/WordPress/WordPress/compare/3.9...3.9.1" rel="nofollow">https://github.com/WordPress/WordPress/compare/3.9...3.9.1</a> bar',
     421                );
     422                foreach ($urls_before as $key => $url) {
     423                        $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
     424                }
     425        }
    392426}