Make WordPress Core

Ticket #27587: prior-work.patch

File prior-work.patch, 3.3 KB (added by miqrogroove, 11 years ago)
  • src/wp-includes/formatting.php

     
    19091909         */
    19101910        $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
    19111911
    1912         return sprintf( ' <img src="%s" alt="%s" class="wp-smiley" /> ', esc_url( $src_url ), esc_attr( $smiley ) );
     1912        return sprintf( '<img src="%s" alt="%s" class="wp-smiley" />', esc_url( $src_url ), esc_attr( $smiley ) );
    19131913}
    19141914
    19151915/**
  • src/wp-includes/functions.php

     
    25662566         */
    25672567        krsort($wpsmiliestrans);
    25682568
    2569         $wp_smiliessearch = '/((?:\s|^)';
     2569        $spaces = wp_spaces_regexp();
     2570 
     2571        // Begin first "subpattern"
     2572        $wp_smiliessearch = '/(?<=' . $spaces . '|^)';
    25702573
    25712574        $subchar = '';
    25722575        foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
     
    25762579                // new subpattern?
    25772580                if ($firstchar != $subchar) {
    25782581                        if ($subchar != '') {
    2579                                 $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ;
     2582                                $wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern"
     2583                                $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
    25802584                        }
    25812585                        $subchar = $firstchar;
    25822586                        $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
     
    25862590                $wp_smiliessearch .= preg_quote($rest, '/');
    25872591        }
    25882592
    2589         $wp_smiliessearch .= ')(?=\s|$))/m';
     2593        $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
    25902594
    25912595}
    25922596
  • tests/phpunit/tests/formatting/Smilies.php

     
    275275
    276276                $wpsmiliestrans = $orig_trans; // reset original translations array
    277277        }
    278 }
    279  No newline at end of file
     278
     279        /**
     280         * Check that $wp_smiliessearch pattern will match smilies
     281         * between spaces, but never capture those spaces.
     282         *
     283         * Further check that spaces aren't randomly deleted
     284         * or added when replacing the text with an image.
     285         *
     286         * @ticket 22692
     287         */
     288        function test_spaces_around_smilies() {
     289                $nbsp = "\xC2\xA0";
     290
     291                $input  = array();
     292                $output = array();
     293
     294                $input[]  = 'My test :) smile';
     295                $output[] = array('test <img ', 'alt=":)"', ' /> smile');
     296
     297                $input[]  = 'My test ;) smile';
     298                $output[] = array('test <img ', 'alt=";)"', ' /> smile');
     299
     300                $input[]  = 'My test &nbsp;:)&nbsp;smile';
     301                $output[] = array('test &nbsp;<img ', 'alt=":)"', ' />&nbsp;smile');
     302
     303                $input[]  = 'My test &nbsp;;)&nbsp;smile';
     304                $output[] = array('test &nbsp;<img ', 'alt=";)"', ' />&nbsp;smile');
     305
     306                $input[]  = "My test {$nbsp}:){$nbsp}smile";
     307                $output[] = array("test {$nbsp}<img ", 'alt=":)"', " />{$nbsp}smile");
     308
     309                $input[]  = "My test {$nbsp};){$nbsp}smile";
     310                $output[] = array("test {$nbsp}<img ", 'alt=";)"', " />{$nbsp}smile");
     311
     312                foreach($input as $key => $in) {
     313                        $result = convert_smilies( $in );
     314                        foreach($output[$key] as $out) {
     315
     316                                // Each output element must appear in the results.
     317                                $this->assertContains( $out, $result );
     318
     319                        }
     320                }
     321        }
     322}