Make WordPress Core

Changeset 28971


Ignore:
Timestamp:
07/03/2014 04:21:18 PM (12 years ago)
Author:
SergeyBiryukov
Message:

Fix texturization of quotes when enclosed by angle brackets.

props miqrogroove.
fixes #28718.

Location:
trunk
Files:
2 edited

Legend:

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

    r28929 r28971  
    105105                // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
    106106                if ( "'" !== $apos || "'" !== $closing_single_quote ) {
    107                         $dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote;
     107                        $dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote;
    108108                }
    109 
    110109                if ( "'" !== $apos || '"' !== $closing_quote ) {
    111                         $dynamic[ '/\'(\d\d)"(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote;
     110                        $dynamic[ '/\'(\d\d)"(?=\Z|[.,)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote;
    112111                }
    113112
     
    127126                // Single quote at start, or preceded by (, {, <, [, ", -, or spaces.
    128127                if ( "'" !== $opening_single_quote ) {
    129                         $dynamic[ '/(?<=\A|[([{<"\-]|' . $spaces . ')\'/' ] = $opening_single_quote;
     128                        $dynamic[ '/(?<=\A|[([{"\-]|&lt;|' . $spaces . ')\'/' ] = $opening_single_quote;
    130129                }
    131130
    132131                // Apostrophe in a word.  No spaces, double apostrophes, or other punctuation.
    133132                if ( "'" !== $apos ) {
    134                         $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}<>[\]\-]|' . $spaces . ')/' ] = $apos;
     133                        $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
    135134                }
    136135
     
    147146                // Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
    148147                if ( '"' !== $opening_quote ) {
    149                         $dynamic[ '/(?<=\A|[([{<\-]|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
     148                        $dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
    150149                }
    151150
     
    157156                // Single quotes followed by spaces or ending punctuation.
    158157                if ( "'" !== $closing_single_quote ) {
    159                         $dynamic[ '/\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $closing_single_quote;
     158                        $dynamic[ '/\'(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote;
    160159                }
    161160
  • trunk/tests/phpunit/tests/formatting/WPTexturize.php

    r28860 r28971  
    118118                //$this->assertEquals('&#8220;Class of 99&#8221;', wptexturize("\"Class of 99\""));
    119119                $this->assertEquals('&#8220;Class of &#8217;99&#8221;', wptexturize("\"Class of '99\""));
     120                $this->assertEquals('{&#8220;Class of &#8217;99&#8221;}', wptexturize("{\"Class of '99\"}"));
     121                $this->assertEquals(' &#8220;Class of &#8217;99&#8221; ', wptexturize(" \"Class of '99\" "));
     122                $this->assertEquals('}&#8221;Class of &#8217;99&#8243;{', wptexturize("}\"Class of '99\"{")); // Not a quotation, may be between two other quotations.
    120123        }
    121124
     
    347350                        ),
    348351                        array(
    349                                 "word <'word word", // Invalid HTML input?
    350                                 "word <&#8216;word word",
    351                         ),
    352                         array(
    353                                 "word &lt;'word word", // Valid HTML input triggers the apos in a word pattern
    354                                 "word &lt;&#8217;word word",
     352                                "word <'word word", // Invalid HTML input triggers the apos in a word pattern.
     353                                "word <&#8217;word word",
     354                        ),
     355                        array(
     356                                "word &lt;'word word", // Valid HTML input makes curly quotes.
     357                                "word &lt;&#8216;word word",
    355358                        ),
    356359                        array(
     
    376379                        array(
    377380                                "word<'word word",
    378                                 "word<&#8216;word word",
     381                                "word<&#8217;word word",
    379382                        ),
    380383                        array(
    381384                                "word&lt;'word word",
    382                                 "word&lt;&#8217;word word",
     385                                "word&lt;&#8216;word word",
    383386                        ),
    384387                        array(
     
    403406                        ),
    404407                        array(
    405                                 "word <' word word", // Invalid HTML input?
    406                                 "word <&#8216; word word",
    407                         ),
    408                         array(
    409                                 "word &lt;' word word", // Valid HTML input triggers the closing single quote here
    410                                 "word &lt;&#8217; word word",
     408                                "word <' word word",
     409                                "word <&#8217; word word",
     410                        ),
     411                        array(
     412                                "word &lt;' word word",
     413                                "word &lt;&#8216; word word",
    411414                        ),
    412415                        array(
     
    432435                        array(
    433436                                "word<' word word",
    434                                 "word<&#8216; word word",
     437                                "word<&#8217; word word",
    435438                        ),
    436439                        array(
    437440                                "word&lt;' word word",
    438                                 "word&lt;&#8217; word word",
     441                                "word&lt;&#8216; word word",
    439442                        ),
    440443                        array(
     
    534537                        ),
    535538                        array(
    536                                 "word word'. word", // Quotes with outside punctuation could end with apostrophes instead of closing quotes (may affect i18n)
    537                                 "word word&#8217;. word",
    538                         ),
    539                         array(
    540                                 "word ]'. word",
    541                                 "word ]&#8217;. word",
    542                         ),
    543                         array(
    544                                 "word )'. word",
    545                                 "word )&#8217;. word",
    546                         ),
    547                         array(
    548                                 "word }'. word",
    549                                 "word }&#8217;. word",
    550                         ),
    551                         array(
    552                                 "word >'. word", // Not tested
    553                                 "word >&#8217;. word",
    554                         ),
    555                         array(
    556                                 "word &gt;'. word",
    557                                 "word &gt;&#8217;. word",
    558                         ),
    559                 );
    560         }
    561 
    562         /**
    563          * Double quote after a space or ([{< becomes &#8220; (opening_quote) if not followed by spaces
     539                                "word'[ word", // Apostrophes are never followed by opening punctuation.
     540                                "word'[ word",
     541                        ),
     542                        array(
     543                                "word'( word",
     544                                "word'( word",
     545                        ),
     546                        array(
     547                                "word'{ word",
     548                                "word'{ word",
     549                        ),
     550                        array(
     551                                "word'&lt; word",
     552                                "word'&lt; word",
     553                        ),
     554                        array(
     555                                "word'< word", // Invalid HTML input does trigger the apos pattern.
     556                                "word&#8217;< word",
     557                        ),
     558                );
     559        }
     560
     561        /**
     562         * Double quote after a space or ([-{< becomes &#8220; (opening_quote) if not followed by spaces
    564563         *
    565564         * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
     
    587586                        ),
    588587                        array(
    589                                 'word <"word word', // Invalid HTML input?
    590                                 'word <&#8220;word word',
    591                         ),
    592                         array(
    593                                 'word &lt;"word word', // Valid HTML input triggers the closing quote pattern
    594                                 'word &lt;&#8221;word word',
     588                                'word <"word word', // Invalid HTML input triggers the closing quote pattern.
     589                                'word <&#8221;word word',
     590                        ),
     591                        array(
     592                                'word &lt;"word word',
     593                                'word &lt;&#8220;word word',
    595594                        ),
    596595                        array(
     
    599598                        ),
    600599                        array(
     600                                'word -"word word',
     601                                'word -&#8220;word word',
     602                        ),
     603                        array(
     604                                'word-"word word',
     605                                'word-&#8220;word word',
     606                        ),
     607                        array(
    601608                                '"word word',
    602609                                '&#8220;word word',
     
    611618                        ),
    612619                        array(
    613                                 'word<"word word', // Invalid HTML input?
    614                                 'word<&#8220;word word',
    615                         ),
    616                         array(
    617                                 'word&lt;"word word', // Valid HTML input triggers the closing quote pattern
    618                                 'word&lt;&#8221;word word',
     620                                'word<"word word',
     621                                'word<&#8221;word word',
     622                        ),
     623                        array(
     624                                'word&lt;"word word',
     625                                'word&lt;&#8220;word word',
    619626                        ),
    620627                        array(
     
    699706
    700707        /**
    701          * Test that single quotes followed by a space or a period become &#8217; (closing_single_quote)
     708         * Test that single quotes followed by a space or .,-)}]> become &#8217; (closing_single_quote)
    702709         *
    703710         * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
     
    727734                                "word word', she said",
    728735                                "word word&#8217;, she said",
     736                        ),
     737                        array(
     738                                "word word'- word",
     739                                "word word&#8217;- word",
     740                        ),
     741                        array(
     742                                "word word') word",
     743                                "word word&#8217;) word",
     744                        ),
     745                        array(
     746                                "word word'} word",
     747                                "word word&#8217;} word",
     748                        ),
     749                        array(
     750                                "word word'] word",
     751                                "word word&#8217;] word",
     752                        ),
     753                        array(
     754                                "word word'&gt; word",
     755                                "word word&#8217;&gt; word",
    729756                        ),
    730757                        array(
Note: See TracChangeset for help on using the changeset viewer.