Make WordPress Core

Ticket #22625: 22625.patch

File 22625.patch, 2.4 KB (added by chriscct7, 10 years ago)
  • src/wp-includes/formatting.php

     
    17941794        // WP bug fix for LOVE <3 (and other situations with '<' before a number)
    17951795        $text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
    17961796
    1797         while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) {
     1797        while ( preg_match("/<(\/?[\w:]+)\s*([^>]*)>/", $text, $regex) ) {
    17981798                $newtext .= $tagqueue;
    17991799
    18001800                $i = strpos($text, $regex[0]);
     
    18711871                                $tag = '';
    18721872                        }
    18731873                }
    1874                 $newtext .= substr($text, 0, $i) . $tag;
     1874                $newtext .= str_replace( '<', '&lt;', substr($text, 0, $i)) . $tag;
    18751875                $text = substr($text, $i + $l);
    18761876        }
    18771877
     
    18791879        $newtext .= $tagqueue;
    18801880
    18811881        // Add Remaining text
    1882         $newtext .= $text;
     1882        $newtext .= str_replace( '<', '&lt;', $text );
    18831883
    18841884        // Empty Stack
    18851885        while( $x = array_pop($tagstack) )
  • tests/phpunit/tests/formatting/balanceTags.php

     
    204204                }
    205205        }
    206206
     207        /**
     208         * @ticket 22625
     209         **/
     210
     211        function test_encodes_lone_anglebracket() {
     212                $inputs = array(
     213                    'This is < That. <blockquote>foo</blockquote> Text <a href="#">link</a>. Post-link text.',
     214                    'This is <blockquote>foo</blockquote> < that.',
     215                    'This is <blockquote>foo < bar</blockquote> that.',
     216                    '< blockquote > < foo < blockquote >',
     217                    'This is <blockquote>foo < < < bar</blockquote> that.',
     218                    '<<blockquote>foo<</blockquote><',
     219                    '<p>I <3 WordPress',
     220                    '<3<div>foo',
     221                );
     222                $expected = array(
     223                    'This is &lt; That. <blockquote>foo</blockquote> Text <a href="#">link</a>. Post-link text.',
     224                    'This is <blockquote>foo</blockquote> &lt; that.',
     225                    'This is <blockquote>foo &lt; bar</blockquote> that.',
     226                    '&lt; blockquote > &lt; foo &lt; blockquote >',
     227                    'This is <blockquote>foo &lt; &lt; &lt; bar</blockquote> that.',
     228                    '&lt;<blockquote>foo&lt;</blockquote>&lt;',
     229                    '<p>I &lt;3 WordPress</p>',
     230                    '&lt;3<div>foo</div>',
     231                );
     232
     233                foreach ( $inputs as $key => $input ) {
     234                        $this->assertEquals( $expected[$key], balanceTags( $inputs[$key], true ) );
     235                }
     236        }
    207237}