Make WordPress Core


Ignore:
Timestamp:
06/17/2014 05:56:08 PM (10 years ago)
Author:
wonderboymusic
Message:

Add Unit Tests for i18n and wptexturize(). Don't confuse closing single quotes and apostrophes.

See #27426.

File:
1 edited

Legend:

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

    r28761 r28762  
    2525 *
    2626 * @param string $text The text to be formatted
     27 * @param bool $reset Set to true for unit testing. Translated patterns will reset.
    2728 * @return string The string replaced with html entities
    2829 */
    29 function wptexturize($text) {
     30function wptexturize($text, $reset = false) {
    3031    global $wp_cockneyreplace;
    3132    static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements,
    3233        $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true;
    3334
    34     if ( false === $run_texturize ) {
     35    // If there's nothing to do, just stop.
     36    if ( empty( $text ) || false === $run_texturize ) {
    3537        return $text;
    3638    }
    3739
    38     // No need to set up these static variables more than once
    39     if ( ! isset( $static_characters ) ) {
     40    // Set up static variables. Run once only.
     41    if ( $reset || ! isset( $static_characters ) ) {
    4042        /**
    4143         * Filter whether to skip running `wptexturize()`.
     
    124126        }
    125127
    126         // Apostrophe in a word.  No spaces or double apostrophes.
     128        // Apostrophe in a word.  No spaces, double apostrophes, or other punctuation.
    127129        if ( "'" != $apos ) {
    128             $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|\'|' . $spaces . ')/' ] = $apos;
     130            $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}<>[\]\-]|' . $spaces . ')/' ] = $apos;
    129131        }
    130132
     
    149151        }
    150152
    151         // Single quotes followed by spaces or a period.
    152         if ( "'" !== $closing_single_quote ) {
    153             $dynamic[ '/\'(?=\Z|\.|' . $spaces . ')/' ] = $closing_single_quote;
     153        // Single quotes followed by spaces or ending punctuation.
     154        if ( "'" != $closing_single_quote ) {
     155            $dynamic[ '/\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $closing_single_quote;
    154156        }
    155157
     
    162164        $dynamic_characters = array_keys( $dynamic );
    163165        $dynamic_replacements = array_values( $dynamic );
    164     }
    165 
    166     // If there's nothing to do, just stop.
    167     if ( empty( $text ) ) {
    168         return $text;
    169166    }
    170167
Note: See TracChangeset for help on using the changeset viewer.