Ticket #27587: miqro-27587.2.patch
File miqro-27587.2.patch, 17.3 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 /** … … 3864 3864 } 3865 3865 3866 3866 return $spaces; 3867 } 3868 No newline at end of file 3867 } -
src/wp-includes/functions.php
2713 2713 */ 2714 2714 krsort($wpsmiliestrans); 2715 2715 2716 $ wp_smiliessearch = '/((?:\s|^)';2716 $spaces = wp_spaces_regexp(); 2717 2717 2718 // Begin first "subpattern" 2719 $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; 2720 2718 2721 $subchar = ''; 2719 2722 foreach ( (array) $wpsmiliestrans as $smiley => $img ) { 2720 2723 $firstchar = substr($smiley, 0, 1); … … 2723 2726 // new subpattern? 2724 2727 if ($firstchar != $subchar) { 2725 2728 if ($subchar != '') { 2726 $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ; 2729 $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern" 2730 $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern" 2727 2731 } 2728 2732 $subchar = $firstchar; 2729 2733 $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; … … 2733 2737 $wp_smiliessearch .= preg_quote($rest, '/'); 2734 2738 } 2735 2739 2736 $wp_smiliessearch .= ')(?= \s|$))/m';2740 $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; 2737 2741 2738 2742 } 2739 2743 … … 4419 4423 } 4420 4424 4421 4425 return (bool) $var; 4422 } 4423 No newline at end of file 4426 } -
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\" />\n<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 } … … 96 92 */ 97 93 function test_convert_custom_smilies ( $in_txt, $converted_txt ) { 98 94 global $wpsmiliestrans; 99 $trans_orig = $wpsmiliestrans; // save original translations array100 95 101 96 // custom smilies, use_smilies: ON 102 97 update_option( 'use_smilies', 1 ); 98 99 if ( !isset( $wpsmiliestrans ) ) { 100 smilies_init(); 101 } 102 103 $trans_orig = $wpsmiliestrans; // save original translations array 104 103 105 $wpsmiliestrans = array( 104 106 ':PP' => 'icon_tongue.gif', 105 107 ':arrow:' => 'icon_arrow.gif', … … 142 144 * @dataProvider get_smilies_ignore_tags 143 145 */ 144 146 public function test_ignore_smilies_in_tags( $element ) { 145 global $wpsmiliestrans;146 $trans_orig = $wpsmiliestrans; // save original translations array147 148 147 $includes_path = includes_url("images/smilies/"); 149 148 150 149 $in_str = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>'; 151 $exp_str = 'Do we ingore smilies <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" /> 150 $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 . '>'; 152 151 153 152 // standard smilies, use_smilies: ON 154 153 update_option( 'use_smilies', 1 ); … … 158 157 159 158 // standard smilies, use_smilies: OFF 160 159 update_option( 'use_smilies', 0 ); 161 162 $wpsmiliestrans = $trans_orig; // reset original translations array163 160 } 164 161 165 162 /** … … 172 169 return array ( 173 170 array ( 174 171 '8-O :-(', 175 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" />'172 '<img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" />' 176 173 ), 177 174 array ( 178 175 '8-) 8-O', 179 ' <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" />'176 '<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" />' 180 177 ), 181 178 array ( 182 179 '8-) 8O', 183 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" />'180 '<img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" />' 184 181 ), 185 182 array ( 186 183 '8-) :-(', 187 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" />'184 '<img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" />' 188 185 ), 189 186 array ( 190 187 '8-) :twisted:', 191 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" />'188 '<img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" />' 192 189 ), 193 190 array ( 194 191 '8O :twisted: :( :? :(', 195 ' <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" />'192 '<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" />' 196 193 ), 197 194 ); 198 195 } … … 205 202 * @dataProvider get_smilies_combinations 206 203 */ 207 204 public function test_smilies_combinations( $in_txt, $converted_txt ) { 208 global $wpsmiliestrans;209 210 205 // custom smilies, use_smilies: ON 211 206 update_option( 'use_smilies', 1 ); 212 207 smilies_init(); … … 233 228 ), 234 229 array ( 235 230 '8O :) additional text here :)', 236 '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" />'231 '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" />' 237 232 ), 238 233 array ( 239 234 ':) :) :) :)', 240 ' <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" />'235 '<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" />' 241 236 ), 242 237 ); 243 238 } … … 251 246 */ 252 247 public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) { 253 248 global $wpsmiliestrans; 254 $orig_trans = $wpsmiliestrans; // save original tranlations array255 249 256 250 // standard smilies, use_smilies: ON 257 251 update_option( 'use_smilies', 1 ); 258 252 253 if ( !isset( $wpsmiliestrans ) ) { 254 smilies_init(); 255 } 256 257 $orig_trans = $wpsmiliestrans; // save original tranlations array 258 259 259 $wpsmiliestrans = array ( 260 260 ':)' => 'icon_smile.gif' 261 261 ); … … 271 271 272 272 $wpsmiliestrans = $orig_trans; // reset original translations array 273 273 } 274 } 275 No newline at end of file 274 275 /** 276 * Check that $wp_smiliessearch pattern will match smilies 277 * between spaces, but never capture those spaces. 278 * 279 * Further check that spaces aren't randomly deleted 280 * or added when replacing the text with an image. 281 * 282 * @ticket 22692 283 */ 284 function test_spaces_around_smilies() { 285 $nbsp = "\xC2\xA0"; 286 287 // standard smilies, use_smilies: ON 288 update_option( 'use_smilies', 1 ); 289 smilies_init(); 290 291 $input = array(); 292 $output = array(); 293 294 $input[] = 'My test :) smile'; 295 $output[] = array('test <img ', 'alt=":)"', ' /> smile'); 296 297 $input[] = 'My test ;) smile'; 298 $output[] = array('test <img ', 'alt=";)"', ' /> smile'); 299 300 $input[] = 'My test :) smile'; 301 $output[] = array('test <img ', 'alt=":)"', ' /> smile'); 302 303 $input[] = 'My test ;) smile'; 304 $output[] = array('test <img ', 'alt=";)"', ' /> smile'); 305 306 $input[] = "My test {$nbsp}:){$nbsp}smile"; 307 $output[] = array("test {$nbsp}<img ", 'alt=":)"', " />{$nbsp}smile"); 308 309 $input[] = "My test {$nbsp};){$nbsp}smile"; 310 $output[] = array("test {$nbsp}<img ", 'alt=";)"', " />{$nbsp}smile"); 311 312 foreach($input as $key => $in) { 313 $result = convert_smilies( $in ); 314 foreach($output[$key] as $out) { 315 316 // Each output element must appear in the results. 317 $this->assertContains( $out, $result ); 318 319 } 320 } 321 322 // standard smilies, use_smilies: OFF 323 update_option( 'use_smilies', 0 ); 324 } 325 }