Make WordPress Core

Ticket #23756: 23756.5.diff

File 23756.5.diff, 3.9 KB (added by sirbrillig, 11 years ago)

Re-added @ to ticket number in test.

  • src/wp-includes/formatting.php

     
    16011601function make_clickable( $text ) {
    16021602        $r = '';
    16031603        $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags
     1604        $nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
    16041605        foreach ( $textarr as $piece ) {
    1605                 if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) {
     1606
     1607                if ( preg_match( '|^<code[\s>]|', $piece ) || preg_match( '|^<pre[\s>]|', $piece ) )
     1608                        $nested_code_pre++;
     1609                elseif ( ( '</code>' === $piece || '</pre>' === $piece ) && $nested_code_pre )
     1610                        $nested_code_pre--;
     1611
     1612                if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
    16061613                        $r .= $piece;
    16071614                        continue;
    16081615                }
  • tests/phpunit/tests/formatting/MakeClickable.php

     
    289289        }
    290290
    291291        /**
     292         * @ticket 23756
     293         */
     294        function test_no_links_inside_pre_or_code() {
     295                $before = array(
     296                        '<pre>http://wordpress.org</pre>',
     297                        '<code>http://wordpress.org</code>',
     298                        '<pre class="foobar" id="foo">http://wordpress.org</pre>',
     299                        '<code class="foobar" id="foo">http://wordpress.org</code>',
     300                        '<precustomtag>http://wordpress.org</precustomtag>',
     301                        '<codecustomtag>http://wordpress.org</codecustomtag>',
     302                        'URL before pre http://wordpress.org<pre>http://wordpress.org</pre>',
     303                        'URL before code http://wordpress.org<code>http://wordpress.org</code>',
     304                        'URL after pre <pre>http://wordpress.org</pre>http://wordpress.org',
     305                        'URL after code <code>http://wordpress.org</code>http://wordpress.org',
     306                        'URL before and after pre http://wordpress.org<pre>http://wordpress.org</pre>http://wordpress.org',
     307                        'URL before and after code http://wordpress.org<code>http://wordpress.org</code>http://wordpress.org',
     308                        'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
     309                );
     310
     311                $expected = array(
     312                        '<pre>http://wordpress.org</pre>',
     313                        '<code>http://wordpress.org</code>',
     314                        '<pre class="foobar" id="foo">http://wordpress.org</pre>',
     315                        '<code class="foobar" id="foo">http://wordpress.org</code>',
     316                        '<precustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></precustomtag>',
     317                        '<codecustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></codecustomtag>',
     318                        'URL before pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre>',
     319                        'URL before code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code>',
     320                        'URL after pre <pre>http://wordpress.org</pre><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     321                        'URL after code <code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     322                        'URL before and after pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     323                        'URL before and after code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     324                        'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
     325                );
     326
     327                foreach ($before as $key => $url) {
     328                        $this->assertEquals($expected[$key], make_clickable($url));
     329                }
     330        }
     331
     332        /**
    292333         * @ticket 16892
    293334         */
    294335        function test_click_inside_html() {