WordPress.org

Make WordPress Core

Changeset 16280


Ignore:
Timestamp:
11/10/10 19:23:57 (3 years ago)
Author:
westi
Message:

Improved RegEx for quote matching in wptexturize. Fixes #4539 and #15241 props norbertm.

File:
1 edited

Legend:

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

    r16279 r16280  
    5757        $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace); 
    5858 
    59         $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/'); 
    60         $dynamic_replacements = array('&#8217;$1','&#8217;$1', '$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '&#8217;$1', '$1&#215;$2'); 
    61  
     59        $dynamic_map = array( 
     60            '/\'(\d)/' => '&#8217;$1', // '99 
     61             
     62            '/\'([^\']*)\'([^\']*)\'/' => '&#8216;$1&#8217;$2&#8217;', // 'test's' 
     63             
     64            '/\'([^\']*)\'/' => '&#8216;$1&#8217;', // 'asd' 
     65            '/"([^"]*)"/' => $opening_quote . '$1' . $closing_quote, // "qwe" 
     66             
     67            '/(\w)\'(\w)/' => '$1&#8217;$2', // test's 
     68             
     69            '/(\d)"/' => '$1&#8243;', // 9" -> 9″ 
     70            '/(\d)\'/' => '$1&#8242;', // 9' -> 9′ 
     71             
     72            '/\b(\d+)x(\d+)\b/' => '$1&#215;$2' // 10. 97x34 => 97×34 
     73        ); 
     74         
     75        $dynamic_characters = array_keys($dynamic_map); 
     76        $dynamic_replacements = array_values($dynamic_map); 
     77         
    6278        $static_setup = true; 
    6379    } 
     
    7086    $no_texturize_tags_stack = array(); 
    7187    $no_texturize_shortcodes_stack = array(); 
     88     
     89    $single_quote_state = '&#8216;'; 
     90    $double_quote_state = $opening_quote; 
    7291 
    7392    for ( $i = 0; $i < $stop; $i++ ) { 
     
    81100            // regular expressions 
    82101            $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 
     102            // quotes that span multiple tags & shortcodes 
     103            while (($pos = strpos($curl, '\'')) !== FALSE) { 
     104                $curl = preg_replace('/\'/', $single_quote_state, $curl); 
     105                $single_quote_state = (($single_quote_state == '&#8216;') ? '&#8217;' : '&#8216;'); 
     106            } 
     107            while (($pos = strpos($curl, '"')) !== FALSE) { 
     108                $curl = preg_replace('/"/', $double_quote_state, $curl); 
     109                $double_quote_state = (($double_quote_state == $opening_quote) ? $closing_quote : $opening_quote); 
     110            } 
    83111        } elseif (!empty($curl)) { 
    84112            /* 
Note: See TracChangeset for help on using the changeset viewer.