Ticket #4539: dev-snapshot-2010-11-20.php.diff
| File dev-snapshot-2010-11-20.php.diff, 11.0 KB (added by , 15 years ago) |
|---|
-
wordpress/wp-includes/formatting.php
56 56 $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney); 57 57 $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace); 58 58 59 $dynamic_ characters = array('/\'(\d\d(?:’|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/');60 $dynamic_replacements = array('’$1','’$1', '$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2');59 $dynamic_map = array( 60 '/([\A\s])\'(\d)/' => '$1’$2', // '99 61 61 62 '/([\w\]})])\'([\w])/' => '$1’$2', // test's 63 64 '/\'([^\']*)\'/' => '‘$1’', // 'asd' 65 '/"([^"]*)"/' => $opening_quote . '$1' . $closing_quote, // "qwe" 66 67 '/(\d)\'/' => '$1′', // 9' 68 '/(\d)"/' => '$1″', // 9" 69 70 '/\b(\d+)x(\d+)\b/' => '$1×$2' // 97x34 71 ); 72 73 $dynamic_characters = array_keys( $dynamic_map ); 74 $dynamic_replacements = array_values( $dynamic_map ); 75 62 76 $static_setup = true; 63 77 } 64 78 … … 70 84 $no_texturize_tags_stack = array(); 71 85 $no_texturize_shortcodes_stack = array(); 72 86 87 $single_quote_state = '‘'; 88 $double_quote_state = $opening_quote; 89 90 $text_node_count = 0; 91 $whitespace_before_last_tag = false; 92 73 93 for ( $i = 0; $i < $stop; $i++ ) { 74 94 $curl = $textarr[$i]; 75 95 … … 78 98 // This is not a tag, nor is the texturization disabled 79 99 // static strings 80 100 $curl = str_replace($static_characters, $static_replacements, $curl); 101 // quotes after tags, e.g. <b>somebody</b>'s 102 if ( ( $text_node_count > 0 ) && ( ! $whitespace_before_last_tag ) ) { 103 $curl = preg_replace( '/^(\')/', '’', $curl ); 104 } 81 105 // regular expressions 82 106 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 107 // quotes that span multiple tags & shortcodes 108 while ( ( $pos = strpos( $curl, '\'' ) ) !== false ) { 109 $curl = preg_replace( '/\'/', $single_quote_state, $curl ); 110 $single_quote_state = ( ( '‘' == $single_quote_state ) ? '’' : '‘' ); 111 } 112 while ( ( $pos = strpos($curl, '"' ) ) !== false ) { 113 $curl = preg_replace( '/"/', $double_quote_state, $curl ); 114 $double_quote_state = ( $opening_quote == $double_quote_state ) ? $closing_quote : $opening_quote; 115 } 116 // stats for quotes after tags above 117 $text_node_count++; 118 $whitespace_before_last_tag = ( preg_match('/\s$/', $curl) > 0 ); 83 119 } elseif (!empty($curl)) { 84 120 /* 85 121 * Only call _wptexturize_pushpop_element if first char is correct -
wp-testcase/test_includes_formatting.php
385 385 function test_bracketed_quotes_3810() { 386 386 $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); 387 387 } 388 388 389 389 //WP Ticket #4539 390 390 function test_basic_quotes() { 391 $this->assertNotEquals('‘’', wptexturize("''")); // this does not work as expected due to a static replacement 392 $this->assertEquals('“”', wptexturize('""')); 393 $this->assertEquals('“”', wptexturize("``''")); // this is what causes '' to fail 394 $this->assertEquals('‘ ’', wptexturize("' '")); 395 $this->assertEquals('“ ”', wptexturize('" "')); 396 $this->assertEquals('‘<img src="">’', wptexturize('\'<img src="">\'')); 397 $this->assertEquals('“<img src="">”', wptexturize('"<img src="">"')); 398 $this->assertEquals('Peter’s photo: ‘<img src="">’', wptexturize('Peter\'s photo: \'<img src="">\'')); 399 $this->assertEquals('Peter’s photo: “<img src="">”', wptexturize('Peter\'s photo: "<img src="">"')); 400 391 401 $this->assertEquals('test’s', wptexturize('test\'s')); 392 402 $this->assertEquals('test’s', wptexturize('test\'s')); 393 403 394 404 $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); 395 405 $this->assertEquals('“quoted”', wptexturize('"quoted"')); 406 $this->assertEquals('‘quoted’s’', wptexturize('\'quoted\'s\'')); 407 $this->assertEquals('“quoted’s”', wptexturize('"quoted\'s"')); 396 408 397 409 $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); 398 410 $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); 411 $this->assertEquals('(‘quoted’s’)', wptexturize('(\'quoted\'s\')')); 412 $this->assertEquals('{“quoted’s”}', wptexturize('{"quoted\'s"}')); 399 413 400 414 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); 401 415 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); 416 $this->assertEquals('‘qu(ot)ed’s’', wptexturize('\'qu(ot)ed\'s\'')); 417 $this->assertEquals('“qu{ot}ed’s”', wptexturize('"qu{ot}ed\'s"')); 418 $this->assertEquals('‘qu(ot)’s’', wptexturize('\'qu(ot)\'s\'')); 419 $this->assertEquals('“qu{ot}’s”', wptexturize('"qu{ot}\'s"')); 420 $this->assertEquals('“qu[ot]’s”', wptexturize('"qu[ot]\'s"')); 402 421 403 422 $this->assertEquals('‘test’s quoted’', wptexturize('\'test\'s quoted\'')); 404 423 $this->assertEquals('“test’s quoted”', wptexturize('"test\'s quoted"')); … … 410 429 'That means every moment you’re working on something without it being in the public it’s actually dying.', 411 430 wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") 412 431 ); 432 $this->assertEquals( 433 '‘That means every moment you’re working on something without it being in the public it’s actually dying.’', 434 wptexturize("'That means every moment you're working on something without it being in the public it's actually dying.'") 435 ); 436 $this->assertEquals( 437 '“That means every moment you’re working on something without it being in the public it’s actually dying.”', 438 wptexturize("\"That means every moment you're working on something without it being in the public it's actually dying.\"") 439 ); 440 $this->assertEquals( 441 'That means every moment you’re working on ‘something’ without it being in the public it’s actually dying.', 442 wptexturize("That means every moment you're working on 'something' without it being in the public it's actually dying.") 443 ); 444 $this->assertEquals( 445 'That means every moment you’re working on “something” without it being in the public it’s actually dying.', 446 wptexturize("That means every moment you're working on \"something\" without it being in the public it's actually dying.") 447 ); 413 448 } 414 449 415 450 //WP Ticket #4539 … … 451 486 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); 452 487 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); 453 488 } 454 455 function test_quotes_after_numbers() { 456 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 457 } 458 489 459 490 //WP Ticket #15241 460 491 function test_other_html() { 461 492 $this->knownWPBug(15241); 462 493 $this->assertEquals('‘<strong>', wptexturize("'<strong>")); 494 $this->assertEquals('“<strong>', wptexturize('"<strong>')); 495 $this->assertEquals('‘<strong></strong>’', wptexturize("'<strong></strong>'")); 496 $this->assertEquals('“<strong></strong>”', wptexturize('"<strong></strong>"')); 463 497 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',")); 464 498 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); 465 499 } 466 500 501 //WP Ticket #15241 502 function test_many_single_quotes() { 503 $this->assertEquals('This isn’t inherently bad, but I don’t think it’s normal.', wptexturize("This isn't inherently bad, but I don't think it's normal.")); 504 } 505 506 //WP Ticket #1258 507 function test_enumeration() { 508 $this->assertEquals("‘products’, ‘services’", wptexturize("'products', 'services'")); 509 $this->assertEquals("‘hello’, ‘world’, ’tis", wptexturize("'hello', 'world', 'tis")); 510 $this->assertEquals("‘hello’, ‘world’, ’tis ", wptexturize("'hello', 'world', 'tis ")); 511 } 512 513 //WP Ticket #11275 514 function test_quoting() { 515 $this->assertEquals('She said—“No!”', wptexturize('She said—"No!"')); 516 $this->assertEquals('She said — “No!”', wptexturize('She said — "No!"')); 517 $this->assertEquals('She said—“<a href="#">No!</a>”', wptexturize('She said—"<a href="#">No!</a>"')); 518 $this->assertEquals('She said—“<a href="#">It’s Peter’s!</a>”', wptexturize('She said—"<a href="#">It\'s Peter\'s!</a>"')); 519 $this->assertEquals('She said—“<a href="#">It’s Peter’s!</a>”', wptexturize('She said—"<a href="#">It\'s Peter\'s!</a>"')); 520 } 521 522 //WP Ticket #15444 523 function test_tag_followed_by_quote() { 524 $this->knownWPBug(15444); 525 $this->assertEquals('<a href="#">Jim</a>’s red bike.', wptexturize('<a href="#">Jim</a>\'s red bike.')); 526 $this->assertEquals('‘<a href="#">Jim</a>’s red bike.’', wptexturize('\'<a href="#">Jim</a>\'s red bike.\'')); 527 $this->assertEquals('“<a href="#">Jim</a>’s red bike.”', wptexturize('"<a href="#">Jim</a>\'s red bike."')); 528 $this->assertEquals('<a href="#">Jim</a>’s ‘red bike.’', wptexturize('<a href="#">Jim</a>\'s \'red bike.\'')); 529 $this->assertEquals('<a href="#">Jim</a>’s “red bike.”', wptexturize('<a href="#">Jim</a>\'s "red bike."')); 530 $this->assertEquals('<a href="#">Jim</a>’s ‘<a href="#">red bike</a>.’', wptexturize('<a href="#">Jim</a>\'s \'<a href="#">red bike</a>.\'')); 531 $this->assertEquals('<a href="#">Jim</a>’s “<a href="#">red bike</a>.”', wptexturize('<a href="#">Jim</a>\'s "<a href="#">red bike</a>."')); 532 } 533 467 534 function test_x() { 468 535 $this->assertEquals('14×24', wptexturize("14x24")); 536 $this->assertEquals('‘14×24’', wptexturize("'14x24'")); 537 $this->assertEquals('“14×24”', wptexturize('"14x24"')); 538 $this->assertEquals('‘<a href="#">14×24</a>’', wptexturize('\'<a href="#">14x24</a>\'')); 539 $this->assertEquals('“<a href="#">14×24</a>”', wptexturize('"<a href="#">14x24</a>"')); 469 540 } 470 541 471 542 function test_minutes_seconds() {