Ticket #12690: miqro-12690.3.patch
File miqro-12690.3.patch, 5.5 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 start of element. 164 . '(?(?=!--)' // Is this a comment? 165 . '.+?--\s*>' // Find end of comment 166 . '|' 167 . '.+?>' // Find end of element 168 . ')' 169 . '|' 170 . '\[' // Find start of shortcode. 171 . '\[?' // Shortcodes may begin with [[ 172 . '[^\[\]<>]+' // Shortcodes do not contain other shortcodes or HTML elements. 173 . '\]' // Find end of shortcode. 174 . '\]?' // Shortcodes may end with ]] 175 . ')/s'; 176 177 $textarr = preg_split($regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); 178 157 179 foreach ( $textarr as &$curl ) { 158 if ( empty( $curl ) ) { 159 continue; 160 } 180 // Only call _wptexturize_pushpop_element if $curl is a delimeter. 181 $first = $curl[0]; 182 if ( '<' === $first && '>' === substr($curl, -1) ) { 183 // This is an HTML delimeter. 161 184 162 // Only call _wptexturize_pushpop_element if first char is correct tag opening 163 $first = $curl[0]; 164 if ( '<' === $first ) { 165 _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 166 } elseif ( '[' === $first ) { 185 if ( '<!--' !== substr($curl, 0, 4) ) { 186 _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 187 } 188 189 } elseif ( '[' === $first && 1 === preg_match('/^\[[^\[\]<>]+\]$/', $curl) ) { 190 // This is a shortcode delimeter. 191 167 192 _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); 193 194 } elseif ( '[' === $first && 1 === preg_match('/^\[\[[^\[\]<>]+\]\]$/', $curl) ) { 195 // This is an escaped shortcode delimeter. 196 197 // Do not texturize. 198 // Do not push to the shortcodes stack. 199 168 200 } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) { 201 // This is neither a delimeter, nor is this content inside of no_texturize pairs. Do texturize. 169 202 170 // This is not a tag, nor is the texturization disabled static strings171 203 $curl = str_replace($static_characters, $static_replacements, $curl); 172 173 // regular expressions174 204 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 175 205 176 206 // 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 <br ... /> ...]', 1036 '[gallery <br ... /> …]', 1037 ), 1038 array( 1039 '<br [gallery ...] ... />', 1040 '<br [gallery ...] ... />', 1041 ), 1042 array( 1043 '<br [gallery ...] ... /', 1044 '<br [gallery ...] … /', 1045 ), 1046 array( 1047 '<br ... />', 1048 '<br ... />', 1049 ), 1050 array( 1051 '<br ... />...<br ... />', 1052 '<br ... />…<br ... />', 1053 ), 1054 array( 1055 '[gallery ...]...[gallery ...]', 1056 '[gallery ...]…[gallery ...]', 1057 ), 1058 array( 1059 '[[gallery ...]]', 1060 '[[gallery ...]]', 1061 ), 1062 array( 1063 '[[gallery <br ... /> ...]]', 1064 '[[gallery <br ... /> …]]', 1065 ), 1066 array( 1067 '<br [[gallery ...]] ... />', 1068 '<br [[gallery ...]] ... />', 1069 ), 1070 array( 1071 '<br [[gallery ...]] ... /', 1072 '<br [[gallery ...]] … /', 1073 ), 1074 array( 1075 '[[gallery ...]]...[[gallery ...]]', 1076 '[[gallery ...]]…[[gallery ...]]', 1077 ), 1078 array( 1079 '<!-- ... -->', 1080 '<!-- ... -->', 1081 ), 1082 array( 1083 '<!--...-->', 1084 '<!--...-->', 1085 ), 1086 array( 1087 '<!-- ... -- >', 1088 '<!-- ... -- >', 1089 ), 1090 array( 1091 '<!-- <br /> [gallery] ... -->', 1092 '<!-- <br /> [gallery] ... -->', 1093 ), 1094 array( 1095 '...<!-- ... -->...', 1096 '…<!-- ... -->…', 1097 ), 1098 array( 1099 '[gallery ...]...<!-- ... -->...<br ... />', 1100 '[gallery ...]…<!-- ... -->…<br ... />', 1101 ), 1102 array( 1103 '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', 1104 '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', 1105 ), 1106 ); 1107 } 997 1108 }