Ticket #27587: miqro-27587.patch
File miqro-27587.patch, 17.2 KB (added by , 11 years ago) |
---|
-
src/wp-includes/formatting.php
1909 1909 */ 1910 1910 $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() ); 1911 1911 1912 return sprintf( ' <img src="%s" alt="%s" class="wp-smiley" />', esc_url( $src_url ), esc_attr( $smiley ) );1912 return sprintf( '<img src="%s" alt="%s" class="wp-smiley" />', esc_url( $src_url ), esc_attr( $smiley ) ); 1913 1913 } 1914 1914 1915 1915 /** -
src/wp-includes/functions.php
2566 2566 */ 2567 2567 krsort($wpsmiliestrans); 2568 2568 2569 $wp_smiliessearch = '/((?:\s|^)'; 2569 $spaces = wp_spaces_regexp(); 2570 2571 // Begin first "subpattern" 2572 $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; 2570 2573 2571 2574 $subchar = ''; 2572 2575 foreach ( (array) $wpsmiliestrans as $smiley => $img ) { … … 2576 2579 // new subpattern? 2577 2580 if ($firstchar != $subchar) { 2578 2581 if ($subchar != '') { 2579 $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ; 2582 $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern" 2583 $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern" 2580 2584 } 2581 2585 $subchar = $firstchar; 2582 2586 $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; … … 2586 2590 $wp_smiliessearch .= preg_quote($rest, '/'); 2587 2591 } 2588 2592 2589 $wp_smiliessearch .= ')(?= \s|$))/m';2593 $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; 2590 2594 2591 2595 } 2592 2596 -
tests/phpunit/tests/formatting/Smilies.php
16 16 return array ( 17 17 array ( 18 18 'Lorem ipsum dolor sit amet mauris ;-) Praesent gravida sodales. :lol: Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, :eek: mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, :mrgreen: tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus :?:', 19 'Lorem ipsum dolor sit amet mauris <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" /> Praesent gravida sodales. <img src="' . $includes_path . 'icon_lol.gif" alt=":lol:" class="wp-smiley" /> Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, <img src="' . $includes_path . 'icon_surprised.gif" alt=":eek:" class="wp-smiley" /> mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, <img src="' . $includes_path . 'icon_mrgreen.gif" alt=":mrgreen:" class="wp-smiley" /> tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus <img src="' . $includes_path . 'icon_question.gif" alt=":?:" class="wp-smiley" />'19 'Lorem ipsum dolor sit amet mauris <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" /> Praesent gravida sodales. <img src="' . $includes_path . 'icon_lol.gif" alt=":lol:" class="wp-smiley" /> Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, <img src="' . $includes_path . 'icon_surprised.gif" alt=":eek:" class="wp-smiley" /> mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, <img src="' . $includes_path . 'icon_mrgreen.gif" alt=":mrgreen:" class="wp-smiley" /> tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus <img src="' . $includes_path . 'icon_question.gif" alt=":?:" class="wp-smiley" />' 20 20 ), 21 21 array ( 22 22 '<strong>Welcome to the jungle!</strong> We got fun n games! :) We got everything you want 8-) <em>Honey we know the names :)</em>', 23 '<strong>Welcome to the jungle!</strong> We got fun n games! <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> We got everything you want <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <em>Honey we know the names <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /></em>'23 '<strong>Welcome to the jungle!</strong> We got fun n games! <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> We got everything you want <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <em>Honey we know the names <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /></em>' 24 24 ), 25 25 array ( 26 26 "<strong;)>a little bit of this\na little bit:other: of that :D\n:D a little bit of good\nyeah with a little bit of bad8O", 27 "<strong;)>a little bit of this\na little bit:other: of that <img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" /> <img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" />a little bit of good\nyeah with a little bit of bad8O"27 "<strong;)>a little bit of this\na little bit:other: of that <img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" /> <img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" /> a little bit of good\nyeah with a little bit of bad8O" 28 28 ), 29 29 array ( 30 30 '<strong style="here comes the sun :-D">and I say it\'s allright:D:D', … … 48 48 * when use_smilies = 1 and not when use_smilies = 0 49 49 */ 50 50 function test_convert_standard_smilies( $in_txt, $converted_txt ) { 51 global $wpsmiliestrans;52 53 51 // standard smilies, use_smilies: ON 54 52 update_option( 'use_smilies', 1 ); 55 53 … … 61 59 update_option( 'use_smilies', 0 ); 62 60 63 61 $this->assertEquals( $in_txt, convert_smilies($in_txt) ); 64 65 unset( $wpsmiliestrans );66 62 } 67 63 68 64 /** … … 76 72 return array ( 77 73 array ( 78 74 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:', 79 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. <img src="' . $includes_path . 'icon_shock_the_monkey.gif" alt=":monkey:" class="wp-smiley" /> 75 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. <img src="' . $includes_path . 'icon_shock_the_monkey.gif" alt=":monkey:" class="wp-smiley" />' 80 76 ), 81 77 array ( 82 78 'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:', 83 'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. <img src="' . $includes_path . 'icon_nervou.gif" alt=":nervou:" class="wp-smiley" />'79 'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. <img src="' . $includes_path . 'icon_nervou.gif" alt=":nervou:" class="wp-smiley" />' 84 80 ), 85 81 array ( 86 82 ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP <br />corper. Suspendisse a pellentesque dui, non felis.<a> :arrow: :arrow</a>', 87 ' <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" /> <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" />:arrow</a>'83 ' <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" /> <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> :arrow</a>' 88 84 ), 89 85 ); 90 86 } … … 97 93 */ 98 94 function test_convert_custom_smilies ( $in_txt, $converted_txt ) { 99 95 global $wpsmiliestrans; 100 $trans_orig = $wpsmiliestrans; // save original translations array101 96 102 97 // custom smilies, use_smilies: ON 103 98 update_option( 'use_smilies', 1 ); 99 100 if ( !isset( $wpsmiliestrans ) ) { 101 smilies_init(); 102 } 103 104 $trans_orig = $wpsmiliestrans; // save original translations array 105 104 106 $wpsmiliestrans = array( 105 107 ':PP' => 'icon_tongue.gif', 106 108 ':arrow:' => 'icon_arrow.gif', … … 141 143 * 142 144 * @ticket 16448 143 145 * @dataProvider get_smilies_ignore_tags 144 * @uses $wpsmiliestrans145 146 */ 146 147 public function test_ignore_smilies_in_tags( $element ) { 147 global $wpsmiliestrans;148 $trans_orig = $wpsmiliestrans; // save original translations array149 150 148 $includes_path = includes_url("images/smilies/"); 151 149 152 150 $in_str = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>'; 153 $exp_str = 'Do we ingore smilies <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" /> 151 $exp_str = 'Do we ingore smilies <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" /> in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>'; 154 152 155 153 // standard smilies, use_smilies: ON 156 154 update_option( 'use_smilies', 1 ); … … 160 158 161 159 // standard smilies, use_smilies: OFF 162 160 update_option( 'use_smilies', 0 ); 163 164 $wpsmiliestrans = $trans_orig; // reset original translations array165 161 } 166 162 167 163 /** … … 174 170 return array ( 175 171 array ( 176 172 '8-O :-(', 177 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> 173 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> ' 178 174 ), 179 175 array ( 180 176 '8-) 8-O', 181 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> 177 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> ' 182 178 ), 183 179 array ( 184 180 '8-) 8O', 185 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> 181 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" /> ' 186 182 ), 187 183 array ( 188 184 '8-) :-(', 189 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> 185 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> ' 190 186 ), 191 187 array ( 192 188 '8-) :twisted:', 193 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> 189 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" /> ' 194 190 ), 195 191 array ( 196 192 '8O :twisted: :( :? :(', 197 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" /> 193 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" /> <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":(" class="wp-smiley" /> <img src="' . $includes_path . 'icon_confused.gif" alt=":?" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":(" class="wp-smiley" /> ' 198 194 ), 199 195 ); 200 196 } … … 205 201 * 206 202 * @ticket 20124 207 203 * @dataProvider get_smilies_combinations 208 * @uses $wpsmiliestrans209 204 */ 210 205 public function test_smilies_combinations( $in_txt, $converted_txt ) { 211 global $wpsmiliestrans;212 213 206 // custom smilies, use_smilies: ON 214 207 update_option( 'use_smilies', 1 ); 215 208 smilies_init(); … … 236 229 ), 237 230 array ( 238 231 '8O :) additional text here :)', 239 '8O <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> additional text here <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />'232 '8O <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> additional text here <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />' 240 233 ), 241 234 array ( 242 235 ':) :) :) :)', 243 ' <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />'236 '<img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />' 244 237 ), 245 238 ); 246 239 } … … 255 248 */ 256 249 public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) { 257 250 global $wpsmiliestrans; 258 $orig_trans = $wpsmiliestrans; // save original tranlations array259 251 260 252 // standard smilies, use_smilies: ON 261 253 update_option( 'use_smilies', 1 ); 262 254 255 if ( !isset( $wpsmiliestrans ) ) { 256 smilies_init(); 257 } 258 259 $orig_trans = $wpsmiliestrans; // save original tranlations array 260 263 261 $wpsmiliestrans = array ( 264 262 ':)' => 'icon_smile.gif' 265 263 ); … … 275 273 276 274 $wpsmiliestrans = $orig_trans; // reset original translations array 277 275 } 278 } 279 No newline at end of file 276 277 /** 278 * Check that $wp_smiliessearch pattern will match smilies 279 * between spaces, but never capture those spaces. 280 * 281 * Further check that spaces aren't randomly deleted 282 * or added when replacing the text with an image. 283 * 284 * @ticket 22692 285 */ 286 function test_spaces_around_smilies() { 287 $nbsp = "\xC2\xA0"; 288 289 // standard smilies, use_smilies: ON 290 update_option( 'use_smilies', 1 ); 291 smilies_init(); 292 293 $input = array(); 294 $output = array(); 295 296 $input[] = 'My test :) smile'; 297 $output[] = array('test <img ', 'alt=":)"', ' /> smile'); 298 299 $input[] = 'My test ;) smile'; 300 $output[] = array('test <img ', 'alt=";)"', ' /> smile'); 301 302 $input[] = 'My test :) smile'; 303 $output[] = array('test <img ', 'alt=":)"', ' /> smile'); 304 305 $input[] = 'My test ;) smile'; 306 $output[] = array('test <img ', 'alt=";)"', ' /> smile'); 307 308 $input[] = "My test {$nbsp}:){$nbsp}smile"; 309 $output[] = array("test {$nbsp}<img ", 'alt=":)"', " />{$nbsp}smile"); 310 311 $input[] = "My test {$nbsp};){$nbsp}smile"; 312 $output[] = array("test {$nbsp}<img ", 'alt=";)"', " />{$nbsp}smile"); 313 314 foreach($input as $key => $in) { 315 $result = convert_smilies( $in ); 316 foreach($output[$key] as $out) { 317 318 // Each output element must appear in the results. 319 $this->assertContains( $out, $result ); 320 321 } 322 } 323 324 // standard smilies, use_smilies: OFF 325 update_option( 'use_smilies', 0 ); 326 } 327 }