Ticket #22692: miqro-22692.9.patch
| File miqro-22692.9.patch, 10.3 KB (added by , 13 years ago) |
|---|
-
src/wp-includes/formatting.php
73 73 $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney ); 74 74 $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace ); 75 75 76 // Pattern-based replacements of characters. 76 77 $dynamic = array(); 77 if ( "'" != $apos ) { 78 $dynamic[ '/\'(\d\d(?:’|\')?s)/' ] = $apos . '$1'; // '99's 79 $dynamic[ '/\'(\d)/' ] = $apos . '$1'; // '99 80 } 78 $spaces = wp_spaces_regexp(); 79 80 // '99s (apostrophe) 81 if ( "'" != $apos ) 82 $dynamic[ '/\'(?=\d)/' ] = $apos; 83 84 // Single quote at start, or preceded by (, {, <, [, ", or spaces. 81 85 if ( "'" != $opening_single_quote ) 82 $dynamic[ '/(\s|\A|[([{<]|")\'/' ] = '$1' . $opening_single_quote; // opening single quote, even after (, {, <, [ 86 $dynamic[ '/(?<=\A|[([{<"]|' . $spaces . ')\'/' ] = $opening_single_quote; 87 88 // 9" (double prime) 83 89 if ( '"' != $double_prime ) 84 $dynamic[ '/(\d)"/' ] = '$1' . $double_prime; // 9" (double prime) 90 $dynamic[ '/(?<=\d)"/' ] = $double_prime; 91 92 // 9' (prime) 85 93 if ( "'" != $prime ) 86 $dynamic[ '/(\d)\'/' ] = '$1' . $prime; // 9' (prime) 94 $dynamic[ '/(?<=\d)\'/' ] = $prime; 95 96 // Apostrophe in a word. No spaces or double primes. 87 97 if ( "'" != $apos ) 88 $dynamic[ '/(\S)\'([^\'\s])/' ] = '$1' . $apos . '$2'; // apostrophe in a word 98 $dynamic[ '/(?<!' . $spaces . ')\'(?!\'|' . $spaces . ')/' ] = $apos; 99 100 // Double quote at start, or preceded by (, {, <, [, or spaces, and not followed by spaces. 89 101 if ( '"' != $opening_quote ) 90 $dynamic[ '/(\s|\A|[([{<])"(?!\s)/' ] = '$1' . $opening_quote . '$2'; // opening double quote, even after (, {, <, [ 102 $dynamic[ '/(?<=\A|[([{<]|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote; 103 104 // Any remaining double quotes. 91 105 if ( '"' != $closing_quote ) 92 $dynamic[ '/"(\s|\S|\Z)/' ] = $closing_quote . '$1'; // closing double quote 106 $dynamic[ '/"/' ] = $closing_quote; 107 108 // Single quotes followed by spaces or a period. 93 109 if ( "'" != $closing_single_quote ) 94 $dynamic[ '/\'( [\s.]|\Z)/' ] = $closing_single_quote . '$1'; // closing single quote110 $dynamic[ '/\'(?=\Z|\.|' . $spaces . ')/' ] = $closing_single_quote; 95 111 96 $dynamic[ '/\b(\d+)x(\d+)\b/' ] = '$1×$2'; // 9x9 (times) 112 // 9x9 (times) 113 $dynamic[ '/\b(\d+)x(\d+)\b/' ] = '$1×$2'; 97 114 98 115 $dynamic_characters = array_keys( $dynamic ); 99 116 $dynamic_replacements = array_values( $dynamic ); … … 318 335 } 319 336 320 337 $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); 338 $spaces = wp_spaces_regexp(); 321 339 322 340 $pattern = 323 341 '/' 324 342 . '<p>' // Opening paragraph 325 . ' \\s*+'// Optional leading whitespace343 . '(?:' . $spaces . ')*+' // Optional leading whitespace 326 344 . '(' // 1: The shortcode 327 345 . '\\[' // Opening bracket 328 346 . "($tagregexp)" // 2: Shortcode name … … 347 365 . ')?' 348 366 . ')' 349 367 . ')' 350 . ' \\s*+'// optional trailing whitespace368 . '(?:' . $spaces . ')*+' // optional trailing whitespace 351 369 . '<\\/p>' // closing paragraph 352 370 . '/s'; 353 371 … … 1865 1883 */ 1866 1884 $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() ); 1867 1885 1868 return sprintf( ' <img src="%s" alt="%s" class="wp-smiley" />', esc_url( $src_url ), esc_attr( $smiley ) );1886 return sprintf( '<img src="%s" alt="%s" class="wp-smiley" />', esc_url( $src_url ), esc_attr( $smiley ) ); 1869 1887 } 1870 1888 1871 1889 /** … … 3781 3799 3782 3800 return false; 3783 3801 } 3802 3803 /** 3804 * Returns the regexp for common whitespace characters. 3805 * 3806 * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp. 3807 * This is designed to replace the PCRE \s sequence. In ticket #22692, that 3808 * sequence was found to be unreliable due to random inclusion of the A0 byte. 3809 * 3810 * @since 3.9.0 3811 * 3812 * @return string The spaces regexp. 3813 */ 3814 function wp_spaces_regexp() { 3815 static $spaces; 3816 3817 if (empty($spaces)) { 3818 $spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0| ' ); 3819 } 3820 3821 return $spaces; 3822 } -
src/wp-includes/functions.php
2560 2560 */ 2561 2561 krsort($wpsmiliestrans); 2562 2562 2563 $ wp_smiliessearch = '/((?:\s|^)';2563 $spaces = wp_spaces_regexp(); 2564 2564 2565 // Begin first "subpattern" 2566 $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; 2567 2565 2568 $subchar = ''; 2566 2569 foreach ( (array) $wpsmiliestrans as $smiley => $img ) { 2567 2570 $firstchar = substr($smiley, 0, 1); … … 2570 2573 // new subpattern? 2571 2574 if ($firstchar != $subchar) { 2572 2575 if ($subchar != '') { 2573 $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ; 2576 $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern" 2577 $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern" 2574 2578 } 2575 2579 $subchar = $firstchar; 2576 2580 $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; … … 2580 2584 $wp_smiliessearch .= preg_quote($rest, '/'); 2581 2585 } 2582 2586 2583 $wp_smiliessearch .= ')(?= \s|$))/m';2587 $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; 2584 2588 2585 2589 } 2586 2590 -
tests/phpunit/tests/formatting/Smilies.php
275 275 276 276 $wpsmiliestrans = $orig_trans; // reset original translations array 277 277 } 278 } 279 No newline at end of file 278 279 /** 280 * Check that $wp_smiliessearch pattern will match smilies 281 * between spaces, but never capture those spaces. 282 * 283 * Further check that spaces aren't randomly deleted 284 * or added when replacing the text with an image. 285 * 286 * @ticket 22692 287 */ 288 function test_spaces_around_smilies() { 289 $nbsp = "\xC2\xA0"; 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 $k => $out) { 315 316 // Each output element must appear in the results. 317 $this->assertContains( $out[$k], $result ); 318 319 } 320 } 321 } 322 } -
tests/phpunit/tests/formatting/WPTexturize.php
194 194 $this->assertEquals( ' — ', wptexturize( ' -- ' ) ); 195 195 $this->assertEquals( ' — ', wptexturize( ' -- ') ); 196 196 } 197 198 /** 199 * @ticket 22692 200 */ 201 function test_spaces_around_quotes() { 202 $nbsp = "\xC2\xA0"; 203 $pi = "\xCE\xA0"; 204 205 // This should never happen, even if the desired output changes some day. 206 207 $problem_input = "$nbsp\"A"; 208 $problem_output = "$nbsp”A"; 209 210 $this->assertNotEquals( $problem_output, wptexturize( $problem_input ) ); 211 212 // These are desirable outputs for the current design. 213 214 $input = array(); 215 $output = array(); 216 217 $input[] = "stop. $nbsp\"A quote after 2 spaces.\""; 218 $output[] = "stop. $nbsp“A quote after 2 spaces.”"; 219 220 $input[] = "stop.$nbsp$nbsp\"A quote after 2 spaces.\""; 221 $output[] = "stop.$nbsp$nbsp“A quote after 2 spaces.”"; 222 223 $input[] = "stop. $nbsp'A quote after 2 spaces.'"; 224 $output[] = "stop. $nbsp‘A quote after 2 spaces.’"; 225 226 $input[] = "stop.$nbsp$nbsp'A quote after 2 spaces.'"; 227 $output[] = "stop.$nbsp$nbsp‘A quote after 2 spaces.’"; 228 229 $input[] = "stop. \"A quote after 2 spaces.\""; 230 $output[] = "stop. “A quote after 2 spaces.”"; 231 232 $input[] = "stop. \"A quote after 2 spaces.\""; 233 $output[] = "stop. “A quote after 2 spaces.”"; 234 235 $input[] = "stop. 'A quote after 2 spaces.'"; 236 $output[] = "stop. ‘A quote after 2 spaces.’"; 237 238 $input[] = "stop. 'A quote after 2 spaces.'"; 239 $output[] = "stop. ‘A quote after 2 spaces.’"; 240 241 $input[] = "Contraction: $pi's"; 242 $output[] = "Contraction: $pi’s"; 243 244 foreach($input as $key => $in) { 245 $this->assertEquals( $output[$key], wptexturize( $in ) ); 246 } 247 } 197 248 } -
tests/phpunit/tests/shortcode.php
373 373 remove_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts2' ), 10, 3 ); 374 374 } 375 375 376 /** 377 * Check that shortcode_unautop() will always recognize spaces around shortcodes. 378 * 379 * @ticket 22692 380 */ 381 function test_spaces_around_shortcodes() { 382 $nbsp = "\xC2\xA0"; 383 384 $input = array(); 385 386 $input[] = "<p>[gallery ids=\"37,15,11\"]</p>"; 387 $input[] = "<p> [gallery ids=\"37,15,11\"] </p>"; 388 $input[] = "<p> $nbsp[gallery ids=\"37,15,11\"] $nbsp</p>"; 389 $input[] = "<p> [gallery ids=\"37,15,11\"] </p>"; 390 391 $output = "[gallery ids=\"37,15,11\"]"; 392 393 foreach($input as $in) { 394 $this->assertEquals( $output, shortcode_unautop( $in ) ); 395 } 396 } 376 397 }