Ticket #12690: miqro-12690.patch
File miqro-12690.patch, 4.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/formatting.php
130 130 $dynamic_replacements = array_values( $dynamic ); 131 131 } 132 132 133 // If there's nothing to do, just stop. 134 if ( empty( $text ) ) { 135 return $text; 136 } 137 133 138 // Transform into regexp sub-expression used in _wptexturize_pushpop_element 134 139 // Must do this every time in case plugins use these filters in a context sensitive manner 135 140 /** … … 152 157 $no_texturize_tags_stack = array(); 153 158 $no_texturize_shortcodes_stack = array(); 154 159 155 $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);160 // Look for shortcodes and HTML elements. 156 161 162 $regex = '/(' // Capture the entire match. 163 . '<[^>]+>' // Find all HTML elements. 164 . '|' 165 . '(?<!\[)' // Shortcodes do not begin with [[ 166 . '\[' // Find start of shortcode. 167 . '[^\[\]<>]+' // Shortcodes do not contain other shortcodes or HTML elements. 168 . '\]' // Find end of shortcode. 169 . '(?!\])' // Shortcodes do not end with ]] 170 . ')/'; 171 172 $textarr = preg_split($regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); 173 157 174 foreach ( $textarr as &$curl ) { 158 if ( empty( $curl ) ) { 159 continue; 160 } 161 162 // Only call _wptexturize_pushpop_element if first char is correct tag opening 175 // Only call _wptexturize_pushpop_element if $curl is a delimeter. 163 176 $first = $curl[0]; 164 if ( '<' === $first ) {177 if ( '<' === $first && '>' === substr($curl, -1) ) { 165 178 _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 166 } elseif ( '[' === $first ) {179 } elseif ( '[' === $first && 1 === preg_match('/^\[[^\[\]<>]+\]$/', $curl) ) { 167 180 _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); 168 181 } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) { 169 182 170 // This is n ot a tag, nor is the texturization disabled static strings183 // This is neither a delimeter, nor is this content inside of no_texturize pairs. 171 184 $curl = str_replace($static_characters, $static_replacements, $curl); 172 173 // regular expressions174 185 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 175 186 176 187 // 9x9 (times) -
tests/phpunit/tests/formatting/WPTexturize.php
994 994 ), 995 995 ); 996 996 } 997 998 /** 999 * Test HTML and shortcode avoidance. 1000 * 1001 * @ticket 12690 1002 * @dataProvider data_tag_avoidance 1003 */ 1004 function test_tag_avoidance( $input, $output ) { 1005 return $this->assertEquals( $output, wptexturize( $input ) ); 1006 } 1007 1008 function data_tag_avoidance() { 1009 return array( 1010 array( 1011 '[ photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy </a> ]', 1012 '[ photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy </a> ], 1013 ), 1014 array( 1015 '[gallery ...]', 1016 '[gallery ...]', 1017 ), 1018 array( 1019 '[gal>ery ...]', 1020 '[gal>ery …]', 1021 ), 1022 array( 1023 '[gallery ...', 1024 '[gallery …', 1025 ), 1026 array( 1027 '[[gallery ...]]', 1028 '[[gallery …]]', 1029 ), 1030 array( 1031 '[[gallery ...]', 1032 '[[gallery …]', 1033 ), 1034 array( 1035 '[gallery ...]]', 1036 '[gallery …]]', 1037 ), 1038 array( 1039 '[gallery <br ... /> ...]', 1040 '[gallery <br ... /> …]', 1041 ), 1042 array( 1043 '<br [gallery ...] ... />', 1044 '<br [gallery ...] ... />', 1045 ), 1046 array( 1047 '<br [gallery ...] ... /', 1048 '<br [gallery ...] … /', 1049 ), 1050 array( 1051 '<br ... />', 1052 '<br ... />', 1053 ), 1054 array( 1055 '<br ... />...<br ... />', 1056 '<br ... />…<br ... />', 1057 ), 1058 array( 1059 '[gallery ...]...[gallery ...]', 1060 '[gallery ...]…[gallery ...]', 1061 ), 1062 ); 1063 } 997 1064 }