Ticket #4539: dev-snapshot-2010-11-21.php.diff
| File dev-snapshot-2010-11-21.php.diff, 15.6 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, 1 ); 110 $single_quote_state = ( ( '‘' == $single_quote_state ) ? '’' : '‘' ); 111 } 112 while ( ( $pos = strpos($curl, '"' ) ) !== false ) { 113 $curl = preg_replace( '/"/', $double_quote_state, $curl, 1 ); 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"]', wptexturize('["quoted"]')); // shortcode 412 $this->assertEquals('<"quoted">', wptexturize('<"quoted">')); // tag 413 $this->assertEquals('(‘quoted’s’)', wptexturize('(\'quoted\'s\')')); 414 $this->assertEquals('{“quoted’s”}', wptexturize('{"quoted\'s"}')); 415 $this->assertEquals('["quoted\'s"]', wptexturize('["quoted\'s"]')); // shortcode 416 $this->assertEquals('<"quoted\'s">', wptexturize('<"quoted\'s">')); // tag 399 417 400 418 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); 401 419 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); 420 $this->assertEquals('“qu[ot]ed”', wptexturize('"qu[ot]ed"')); 421 $this->assertEquals('“qu<ot>ed”', wptexturize('"qu<ot>ed"')); 422 $this->assertEquals('‘qu(ot)ed’s’', wptexturize('\'qu(ot)ed\'s\'')); 423 $this->assertEquals('“qu{ot}ed’s”', wptexturize('"qu{ot}ed\'s"')); 424 $this->assertEquals('“qu[ot]ed’s”', wptexturize('"qu[ot]ed\'s"')); 425 $this->assertEquals('“qu<ot>ed’s”', wptexturize('"qu<ot>ed\'s"')); 426 $this->assertEquals('‘qu(ot)’s’', wptexturize('\'qu(ot)\'s\'')); 427 $this->assertEquals('“qu{ot}’s”', wptexturize('"qu{ot}\'s"')); 428 $this->assertEquals('“qu[ot]’s”', wptexturize('"qu[ot]\'s"')); 429 $this->assertEquals('“qu<ot>’s”', wptexturize('"qu<ot>\'s"')); 402 430 403 431 $this->assertEquals('‘test’s quoted’', wptexturize('\'test\'s quoted\'')); 404 432 $this->assertEquals('“test’s quoted”', wptexturize('"test\'s quoted"')); 405 433 } 406 434 435 //WP Ticket #4539 436 function test_nested_quotes() { 437 $this->assertEquals('“This is a ‘nested quote’.”', wptexturize('"This is a \'nested quote\'."')); 438 $this->assertEquals('‘This is a “nested quote”.’', wptexturize('\'This is a "nested quote".\'')); 439 $this->assertEquals('“These are some ‘nested’ ‘quotes’.”', wptexturize('"These are some \'nested\' \'quotes\'."')); 440 $this->assertEquals('‘These are some “nested” “quotes”.’', wptexturize('\'These are some "nested" "quotes".\'')); 441 } 442 407 443 //WP Tickets #4539, #15241 408 444 function test_full_sentences_with_unmatched_single_quotes() { 409 445 $this->assertEquals( 410 446 'That means every moment you’re working on something without it being in the public it’s actually dying.', 411 447 wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") 412 448 ); 449 $this->assertEquals( 450 '‘That means every moment you’re working on something without it being in the public it’s actually dying.’', 451 wptexturize("'That means every moment you're working on something without it being in the public it's actually dying.'") 452 ); 453 $this->assertEquals( 454 '“That means every moment you’re working on something without it being in the public it’s actually dying.”', 455 wptexturize("\"That means every moment you're working on something without it being in the public it's actually dying.\"") 456 ); 457 $this->assertEquals( 458 'That means every moment you’re working on ‘something’ without it being in the public it’s actually dying.', 459 wptexturize("That means every moment you're working on 'something' without it being in the public it's actually dying.") 460 ); 461 $this->assertEquals( 462 'That means every moment you’re working on “something” without it being in the public it’s actually dying.', 463 wptexturize("That means every moment you're working on \"something\" without it being in the public it's actually dying.") 464 ); 413 465 } 414 466 415 //WP Ticket #4539467 //WP Tickets #4539, #10606 416 468 function test_quotes() { 417 469 $this->knownWPBug(4539); 418 470 $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); 419 471 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"')); 472 $this->assertEquals('Here is “ <a href="http://example.com">a test with a link</a> ”', wptexturize('Here is " <a href="http://example.com">a test with a link</a> "')); 473 $this->assertEquals('Here is “<a href="http://example.com"> a test with a link </a>”', wptexturize('Here is "<a href="http://example.com"> a test with a link </a>"')); 420 474 $this->assertEquals('Here is “<a href="http://example.com">a test with a link and a period</a>”.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".')); 421 475 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>” and a space.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>" and a space.')); 422 476 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a> and some text quoted”', wptexturize('Here is "<a href="http://example.com">a test with a link</a> and some text quoted"')); … … 424 478 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.')); 425 479 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.')); 426 480 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”… and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.')); 481 $this->assertEquals('Here is “<a href="http://example.com">a test</a> with a link”.', wptexturize('Here is "<a href="http://example.com">a test</a> with a link".')); 427 482 $this->assertEquals('Here is “a test <a href="http://example.com">with a link</a>”.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".')); 428 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.')); 483 $this->assertEquals('Here is “a test <a href="http://example.com">with a link</a>” .', wptexturize('Here is "a test <a href="http://example.com">with a link</a>" .')); 484 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”and a word stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a word stuck to the end.')); 429 485 $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); 430 486 $this->assertEquals('A test with a number, “like 62”, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.')); 431 487 } … … 451 507 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); 452 508 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); 453 509 } 454 455 function test_quotes_after_numbers() { 456 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 457 } 458 510 459 511 //WP Ticket #15241 460 512 function test_other_html() { 461 513 $this->knownWPBug(15241); 462 514 $this->assertEquals('‘<strong>', wptexturize("'<strong>")); 515 $this->assertEquals('“<strong>', wptexturize('"<strong>')); 516 $this->assertEquals('‘<strong></strong>’', wptexturize("'<strong></strong>'")); 517 $this->assertEquals('“<strong></strong>”', wptexturize('"<strong></strong>"')); 463 518 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',")); 464 519 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); 465 520 } 466 521 522 //WP Ticket #15241 523 function test_many_single_quotes() { 524 $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.")); 525 } 526 527 //WP Ticket #1258 528 function test_enumeration() { 529 $this->assertEquals("‘products’, ‘services’", wptexturize("'products', 'services'")); 530 $this->assertEquals("‘hello’, ‘world’, ’tis", wptexturize("'hello', 'world', 'tis")); 531 $this->assertEquals("‘hello’, ‘world’, ’tis ", wptexturize("'hello', 'world', 'tis ")); 532 } 533 534 //WP Ticket #11275 535 function test_quoting() { 536 $this->assertEquals('She said—“No!”', wptexturize('She said—"No!"')); 537 $this->assertEquals('She said — “No!”', wptexturize('She said — "No!"')); 538 $this->assertEquals('She said—“<a href="#">No!</a>”', wptexturize('She said—"<a href="#">No!</a>"')); 539 $this->assertEquals('She said—‘<a href="#">It’s Peter’s!</a>’', wptexturize('She said—\'<a href="#">It\'s Peter\'s!</a>\'')); 540 $this->assertEquals('She said—“<a href="#">It’s Peter’s!</a>”', wptexturize('She said—"<a href="#">It\'s Peter\'s!</a>"')); 541 } 542 543 //WP Ticket #15444 544 function test_tag_followed_by_quote() { 545 $this->knownWPBug(15444); 546 $this->assertEquals('<a href="#">Jim</a>’s red bike.', wptexturize('<a href="#">Jim</a>\'s red bike.')); 547 $this->assertEquals('‘<a href="#">Jim</a>’s red bike.’', wptexturize('\'<a href="#">Jim</a>\'s red bike.\'')); 548 $this->assertEquals('“<a href="#">Jim</a>’s red bike.”', wptexturize('"<a href="#">Jim</a>\'s red bike."')); 549 $this->assertEquals('<a href="#">Jim</a>’s ‘red bike.’', wptexturize('<a href="#">Jim</a>\'s \'red bike.\'')); 550 $this->assertEquals('<a href="#">Jim</a>’s “red bike.”', wptexturize('<a href="#">Jim</a>\'s "red bike."')); 551 $this->assertEquals('<a href="#">Jim</a>’s ‘<a href="#">red bike</a>.’', wptexturize('<a href="#">Jim</a>\'s \'<a href="#">red bike</a>.\'')); 552 $this->assertEquals('<a href="#">Jim</a>’s “<a href="#">red bike</a>.”', wptexturize('<a href="#">Jim</a>\'s "<a href="#">red bike</a>."')); 553 } 554 467 555 function test_x() { 468 556 $this->assertEquals('14×24', wptexturize("14x24")); 557 $this->assertEquals('‘14×24’', wptexturize("'14x24'")); 558 $this->assertEquals('“14×24”', wptexturize('"14x24"')); 559 $this->assertEquals('‘<a href="#">14×24</a>’', wptexturize('\'<a href="#">14x24</a>\'')); 560 $this->assertEquals('“<a href="#">14×24</a>”', wptexturize('"<a href="#">14x24</a>"')); 469 561 } 470 562 471 563 function test_minutes_seconds() {