WordPress.org

Make WordPress Core

Ticket #11678: 11678.case-insensitive-regex.patch

File 11678.case-insensitive-regex.patch, 3.9 KB (added by kurtpayne, 3 years ago)

Changing regexes to use case-insensitive modifier

  • wp-includes/formatting.php

     
    175175        $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); 
    176176        // Space things out a little 
    177177        $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; 
    178         $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); 
    179         $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee); 
     178        $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!i', "\n$1", $pee); 
     179        $pee = preg_replace('!(</' . $allblocks . '>)!i', "$1\n\n", $pee); 
    180180        $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 
    181181        if ( strpos($pee, '<object') !== false ) { 
    182                 $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed 
    183                 $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee); 
     182                $pee = preg_replace('|\s*<param([^>]*)>\s*|i', "<param$1>", $pee); // no pee inside object/embed 
     183                $pee = preg_replace('|\s*</embed>\s*|i', '</embed>', $pee); 
    184184        } 
    185185        $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates 
    186186        // make paragraphs, including one at the end 
     
    188188        $pee = ''; 
    189189        foreach ( $pees as $tinkle ) 
    190190                $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n"; 
    191         $pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 
    192         $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee); 
    193         $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag 
    194         $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists 
     191        $pee = preg_replace('|<p>\s*</p>|i', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 
     192        $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!i', "<p>$1</p></$2>", $pee); 
     193        $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!i', "$1", $pee); // don't pee all over a tag 
     194        $pee = preg_replace("|<p>(<li.+?)</p>|i", "$1", $pee); // problem with nested lists 
    195195        $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee); 
    196196        $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee); 
    197         $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee); 
    198         $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); 
     197        $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!i', "$1", $pee); 
     198        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!i', "$1", $pee); 
    199199        if ($br) { 
    200                 $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); 
    201                 $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks 
     200                $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/is', '_autop_newline_preservation_helper', $pee); 
     201                $pee = preg_replace('|(?<!<br />)\s*\n|i', "<br />\n", $pee); // optionally make line breaks 
    202202                $pee = str_replace('<WPPreserveNewline />', "\n", $pee); 
    203203        } 
    204         $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee); 
    205         $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee); 
     204        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!i', "$1", $pee); 
     205        $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!i', '$1', $pee); 
    206206        if (strpos($pee, '<pre') !== false) 
    207207                $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee ); 
    208         $pee = preg_replace( "|\n</p>$|", '</p>', $pee ); 
     208        $pee = preg_replace( "|\n</p>$|i", '</p>', $pee ); 
    209209 
    210210        return $pee; 
    211211}