Ticket #4539: dev-snapshot-2010-12-09.php.diff
File dev-snapshot-2010-12-09.php.diff, 21.6 KB (added by , 14 years ago) |
---|
-
wordpress/wp-includes/formatting.php
31 31 static $static_setup = false, $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements; 32 32 $output = ''; 33 33 $curl = ''; 34 $textarr = preg_split('/(< .*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);34 $textarr = preg_split('/(<!--.*-->|<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 35 35 $stop = count($textarr); 36 36 37 37 // No need to set up these variables more than once … … 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 '/(^|\s)\'([^\'\s]+)([^\']*)\'(\d+)\'(\s|$)/' => '$1\'$2$3’$4\'$5', // 'Class of '99' 61 '/(^|\s)\'(\d+)([^\d\'(?:x\d+)]|\'\w|[\]})]|$)/' => '$1’$2$3', // '99, '99's (?: part meaning not '99x11 - see below) 62 '/([\w\]})])\'([\w])/' => '$1’$2', // test's 63 '/\'([^\']*)\'/' => '‘$1’', // 'asd' 64 '/"([^"]*)"/' => $opening_quote . '$1' . $closing_quote, // "qwe" 65 '/(^|\s)(\d)\'/' => '$1$2′', // 9' 66 '/(^|\s)(\d)"/' => '$1$2″', // 9" 67 '/\b(\d+)x(\d+)\b/' => '$1×$2' // 97x34 68 ); 61 69 70 $dynamic_characters = array_keys( $dynamic_map ); 71 $dynamic_replacements = array_values( $dynamic_map ); 72 62 73 $static_setup = true; 63 74 } 64 75 … … 70 81 $no_texturize_tags_stack = array(); 71 82 $no_texturize_shortcodes_stack = array(); 72 83 84 $single_quote_state = '‘'; 85 $double_quote_state = $opening_quote; 86 87 $text_node_count = 0; 88 $whitespace_before_last_tag = false; 89 73 90 for ( $i = 0; $i < $stop; $i++ ) { 74 91 $curl = $textarr[$i]; 75 92 … … 78 95 // This is not a tag, nor is the texturization disabled 79 96 // static strings 80 97 $curl = str_replace($static_characters, $static_replacements, $curl); 98 // quotes after tags, e.g. <b>somebody</b>'s 99 if ( ( $text_node_count > 0 ) && ( ! $whitespace_before_last_tag ) ) { 100 $curl = preg_replace( '/^(\')/', '’', $curl ); 101 } 102 81 103 // regular expressions 82 104 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 105 106 // Quotes that span across multiple tags & shortcodes 107 // Dynamic regexps above ensure that there is at most 1 quote left in the string. 108 // Otherwise, the less efficient preg_replace() within a while loop would be required. 109 if ( strpos( $curl, '\'' ) !== false ) { 110 $curl = str_replace( '\'', $single_quote_state, $curl); 111 $single_quote_state = ( ( '‘' == $single_quote_state ) ? '’' : '‘' ); 112 } 113 if ( strpos($curl, '"' ) !== false ) { 114 $curl = str_replace( '"', $double_quote_state, $curl); 115 $double_quote_state = ( $opening_quote == $double_quote_state ) ? $closing_quote : $opening_quote; 116 } 117 // stats for quotes after tags above 118 $text_node_count++; 119 $whitespace_before_last_tag = ( preg_match('/\s$/', $curl) > 0 ); 83 120 } elseif (!empty($curl)) { 84 121 /* 85 122 * Only call _wptexturize_pushpop_element if first char is correct -
wp-testcase/test_includes_formatting.php
352 352 function test_dashes() { 353 353 $this->assertEquals('Hey — boo?', wptexturize('Hey -- boo?')); 354 354 $this->assertEquals('<a href="http://xx--xx">Hey — boo?</a>', wptexturize('<a href="http://xx--xx">Hey -- boo?</a>')); 355 $this->assertEquals('Hey—boo?', wptexturize('Hey---boo?')); 356 $this->assertEquals('<a href="http://xx---xx">Hey—boo?</a>', wptexturize('<a href="http://xx---xx">Hey---boo?</a>')); 355 357 } 356 358 357 359 function test_disable() { … … 371 373 372 374 $invalid_nest = '<pre></code>"baba"</pre>'; 373 375 $this->assertEquals($invalid_nest, wptexturize($invalid_nest)); 376 } 374 377 378 //WP Ticket #8912, #10033 379 function test_skip_html_comments() { 380 $this->assertEquals('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>')); 381 382 $html = '<!--[if !IE]>-->' . "\n"; 383 $html .= '<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/_nkZ3eHeXlc" width="320" height="260">' . "\n"; 384 $html .= '<!--<![endif]-->' . "\n"; 385 $this->assertEquals($html, wptexturize($html)); 386 387 $html = '<!--[if !IE]>-->' . "\n"; 388 $html .= '</object>' . "\n"; 389 $html .= '<!--<![endif]-->' . "\n"; 390 $this->assertEquals($html, wptexturize($html)); 375 391 } 376 392 377 393 //WP Ticket #1418 … … 388 404 389 405 //WP Ticket #4539 390 406 function test_basic_quotes() { 407 $this->assertNotEquals('‘’', wptexturize("''")); // this does not work as expected due to a static replacement 408 $this->assertEquals('“”', wptexturize('""')); 409 $this->assertEquals('“”', wptexturize("``''")); // this is what causes '' to fail 410 $this->assertEquals('‘ ’', wptexturize("' '")); 411 $this->assertEquals('“ ”', wptexturize('" "')); 412 $this->assertEquals('‘<img src="">’', wptexturize('\'<img src="">\'')); 413 $this->assertEquals('“<img src="">”', wptexturize('"<img src="">"')); 414 $this->assertEquals('Peter’s photo: ‘<img src="">’', wptexturize('Peter\'s photo: \'<img src="">\'')); 415 $this->assertEquals('Peter’s photo: “<img src="">”', wptexturize('Peter\'s photo: "<img src="">"')); 416 391 417 $this->assertEquals('test’s', wptexturize('test\'s')); 392 418 $this->assertEquals('test’s', wptexturize('test\'s')); 393 419 394 420 $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); 395 421 $this->assertEquals('“quoted”', wptexturize('"quoted"')); 422 $this->assertEquals('‘quoted’s’', wptexturize('\'quoted\'s\'')); 423 $this->assertEquals('“quoted’s”', wptexturize('"quoted\'s"')); 396 424 397 425 $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); 398 426 $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); 427 $this->assertEquals('["quoted"]', wptexturize('["quoted"]')); // shortcode 428 $this->assertEquals('<"quoted">', wptexturize('<"quoted">')); // tag 429 $this->assertEquals('(‘quoted’s’)', wptexturize('(\'quoted\'s\')')); 430 $this->assertEquals('{“quoted’s”}', wptexturize('{"quoted\'s"}')); 431 $this->assertEquals('["quoted\'s"]', wptexturize('["quoted\'s"]')); // shortcode 432 $this->assertEquals('<"quoted\'s">', wptexturize('<"quoted\'s">')); // tag 399 433 400 434 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); 401 435 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); 436 $this->assertEquals('“qu[ot]ed”', wptexturize('"qu[ot]ed"')); 437 $this->assertEquals('“qu<ot>ed”', wptexturize('"qu<ot>ed"')); 438 $this->assertEquals('‘qu(ot)ed’s’', wptexturize('\'qu(ot)ed\'s\'')); 439 $this->assertEquals('“qu{ot}ed’s”', wptexturize('"qu{ot}ed\'s"')); 440 $this->assertEquals('“qu[ot]ed’s”', wptexturize('"qu[ot]ed\'s"')); 441 $this->assertEquals('“qu<ot>ed’s”', wptexturize('"qu<ot>ed\'s"')); 442 $this->assertEquals('‘qu(ot)’s’', wptexturize('\'qu(ot)\'s\'')); 443 $this->assertEquals('“qu{ot}’s”', wptexturize('"qu{ot}\'s"')); 444 $this->assertEquals('“qu[ot]’s”', wptexturize('"qu[ot]\'s"')); 445 $this->assertEquals('“qu<ot>’s”', wptexturize('"qu<ot>\'s"')); 402 446 403 447 $this->assertEquals('‘test’s quoted’', wptexturize('\'test\'s quoted\'')); 404 448 $this->assertEquals('“test’s quoted”', wptexturize('"test\'s quoted"')); 405 449 } 450 451 //WP Ticket #4539 452 function test_original_report_4539() { 453 $this->assertEquals("(Bruce Sterling, ’97)", wptexturize("(Bruce Sterling, '97)")); 454 $this->assertEquals("( Bruce Sterling, ’97 )", wptexturize("( Bruce Sterling, '97 )")); 455 $this->assertEquals("<li>Casino Royale ’06</li>", wptexturize("<li>Casino Royale '06</li>")); 456 $this->assertEquals("<li>(Casino Royale ’06)</li>", wptexturize("<li>(Casino Royale '06)</li>")); 457 } 406 458 459 //WP Ticket #14491 460 function test_quoted_numbers() { 461 $this->knownWPBug(14491); 462 463 // 4 digits 464 $this->assertEquals('‘2010’', wptexturize("'2010'")); 465 $this->assertEquals('“2011”', wptexturize('"2011"')); 466 $this->assertEquals('‘ 2010 ’', wptexturize("' 2010 '")); 467 $this->assertEquals('“ 2011 ”', wptexturize('" 2011 "')); 468 $this->assertEquals(' ‘2010’ ', wptexturize(" '2010' ")); 469 $this->assertEquals(' “2011” ', wptexturize(' "2011" ')); 470 $this->assertEquals(' ‘ 2010 ’ ', wptexturize(" ' 2010 ' ")); 471 $this->assertEquals(' “ 2011 ” ', wptexturize(' " 2011 " ')); 472 473 // 2 digits to test against '99' vs '99'ers 474 $this->assertEquals('‘10’', wptexturize("'10'")); 475 $this->assertEquals('“11”', wptexturize('"11"')); 476 $this->assertEquals('‘ 10 ’', wptexturize("' 10 '")); 477 $this->assertEquals('“ 11 ”', wptexturize('" 11 "')); 478 $this->assertEquals(' ‘10’ ', wptexturize(" '10' ")); 479 $this->assertEquals(' “11” ', wptexturize(' "11" ')); 480 $this->assertEquals(' ‘ 10 ’ ', wptexturize(" ' 10 ' ")); 481 $this->assertEquals(' “ 11 ” ', wptexturize(' " 11 " ')); 482 } 483 484 //WP Ticket #4539 485 function test_nested_quotes() { 486 $this->assertEquals('“This is a ‘nested quote’.”', wptexturize('"This is a \'nested quote\'."')); 487 $this->assertEquals('‘This is a “nested quote”.’', wptexturize('\'This is a "nested quote".\'')); 488 $this->assertEquals('“These are some ‘nested’ ‘quotes’.”', wptexturize('"These are some \'nested\' \'quotes\'."')); 489 $this->assertEquals('‘These are some “nested” “quotes”.’', wptexturize('\'These are some "nested" "quotes".\'')); 490 } 491 407 492 //WP Tickets #4539, #15241 408 493 function test_full_sentences_with_unmatched_single_quotes() { 409 494 $this->assertEquals( 410 495 'That means every moment you’re working on something without it being in the public it’s actually dying.', 411 496 wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") 412 497 ); 498 $this->assertEquals( 499 '‘That means every moment you’re working on something without it being in the public it’s actually dying.’', 500 wptexturize("'That means every moment you're working on something without it being in the public it's actually dying.'") 501 ); 502 $this->assertEquals( 503 '“That means every moment you’re working on something without it being in the public it’s actually dying.”', 504 wptexturize("\"That means every moment you're working on something without it being in the public it's actually dying.\"") 505 ); 506 $this->assertEquals( 507 'That means every moment you’re working on ‘something’ without it being in the public it’s actually dying.', 508 wptexturize("That means every moment you're working on 'something' without it being in the public it's actually dying.") 509 ); 510 $this->assertEquals( 511 'That means every moment you’re working on “something” without it being in the public it’s actually dying.', 512 wptexturize("That means every moment you're working on \"something\" without it being in the public it's actually dying.") 513 ); 413 514 } 414 515 415 //WP Ticket #4539516 //WP Tickets #4539, #10606 416 517 function test_quotes() { 417 518 $this->knownWPBug(4539); 418 519 $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); 419 520 $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>"')); 521 $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> "')); 522 $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 523 $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 524 $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 525 $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 527 $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 528 $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 529 $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.')); 530 $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 531 $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.')); 532 $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>" .')); 533 $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 534 $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); 430 535 $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 536 } … … 443 548 //WP Ticket #4539 444 549 function test_quotes_before_numbers() { 445 550 $this->knownWPBug(4539); 551 $this->assertEquals('’99', wptexturize("'99")); 552 553 $this->assertEquals('’99’s', wptexturize("'99’s")); 554 $this->assertEquals('’99’ers', wptexturize("'99’ers")); 555 $this->assertEquals('’749’ers', wptexturize("'749’ers")); 556 557 $this->assertEquals('’99’s', wptexturize("'99's")); 558 $this->assertEquals('’99’ers', wptexturize("'99'ers")); 559 $this->assertEquals('’749’ers', wptexturize("'749'ers")); 560 446 561 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 447 562 $this->assertEquals('Class of ’99’s', wptexturize("Class of '99's")); 563 448 564 $this->assertEquals('‘Class of ’99’', wptexturize("'Class of '99'")); 565 $this->assertEquals(' ‘Class of ’99’ ', wptexturize(" 'Class of '99' ")); 566 $this->assertEquals('‘ Class of ’99 ’', wptexturize("' Class of '99 '")); 567 $this->assertEquals(' ‘ Class of ’99 ’ ', wptexturize(" ' Class of '99 ' ")); 568 449 569 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'")); 450 570 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'")); 571 451 572 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); 452 573 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); 574 $this->assertEquals('“Class of ’99’s”', wptexturize("\"Class of '99's\"")); 453 575 } 454 455 function test_quotes_after_numbers() { 456 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 457 } 458 576 459 577 //WP Ticket #15241 460 578 function test_other_html() { 461 579 $this->knownWPBug(15241); 462 580 $this->assertEquals('‘<strong>', wptexturize("'<strong>")); 581 $this->assertEquals('“<strong>', wptexturize('"<strong>')); 582 $this->assertEquals('‘<strong></strong>’', wptexturize("'<strong></strong>'")); 583 $this->assertEquals('“<strong></strong>”', wptexturize('"<strong></strong>"')); 463 584 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',")); 464 585 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); 465 586 } 466 587 588 //WP Ticket #15241 589 function test_many_single_quotes() { 590 $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.")); 591 } 592 593 //WP Ticket #1258 594 function test_enumeration() { 595 $this->assertEquals("‘products’, ‘services’", wptexturize("'products', 'services'")); 596 $this->assertEquals("‘hello’, ‘world’, ’tis", wptexturize("'hello', 'world', 'tis")); 597 $this->assertEquals("‘hello’, ‘world’, ’tis ", wptexturize("'hello', 'world', 'tis ")); 598 } 599 600 //WP Ticket #11275 601 function test_quoting() { 602 $this->assertEquals('She said—“No!”', wptexturize('She said—"No!"')); 603 $this->assertEquals('She said — “No!”', wptexturize('She said — "No!"')); 604 $this->assertEquals('She said—“<a href="#">No!</a>”', wptexturize('She said—"<a href="#">No!</a>"')); 605 $this->assertEquals('She said—‘<a href="#">It’s Peter’s!</a>’', wptexturize('She said—\'<a href="#">It\'s Peter\'s!</a>\'')); 606 $this->assertEquals('She said—“<a href="#">It’s Peter’s!</a>”', wptexturize('She said—"<a href="#">It\'s Peter\'s!</a>"')); 607 } 608 609 //WP Ticket #15444 610 function test_tag_followed_by_quote() { 611 $this->knownWPBug(15444); 612 $this->assertEquals('<a href="#">Jim</a>’s red bike.', wptexturize('<a href="#">Jim</a>\'s red bike.')); 613 $this->assertEquals('‘<a href="#">Jim</a>’s red bike.’', wptexturize('\'<a href="#">Jim</a>\'s red bike.\'')); 614 $this->assertEquals('“<a href="#">Jim</a>’s red bike.”', wptexturize('"<a href="#">Jim</a>\'s red bike."')); 615 $this->assertEquals('<a href="#">Jim</a>’s ‘red bike.’', wptexturize('<a href="#">Jim</a>\'s \'red bike.\'')); 616 $this->assertEquals('<a href="#">Jim</a>’s “red bike.”', wptexturize('<a href="#">Jim</a>\'s "red bike."')); 617 $this->assertEquals('<a href="#">Jim</a>’s ‘<a href="#">red bike</a>.’', wptexturize('<a href="#">Jim</a>\'s \'<a href="#">red bike</a>.\'')); 618 $this->assertEquals('<a href="#">Jim</a>’s “<a href="#">red bike</a>.”', wptexturize('<a href="#">Jim</a>\'s "<a href="#">red bike</a>."')); 619 } 620 467 621 function test_x() { 468 622 $this->assertEquals('14×24', wptexturize("14x24")); 623 $this->assertEquals(' 14×24', wptexturize(" 14x24")); 624 $this->assertEquals('‘14×24’', wptexturize("'14x24'")); 625 $this->assertEquals('“14×24”', wptexturize('"14x24"')); 626 $this->assertEquals('‘<a href="#">14×24</a>’', wptexturize('\'<a href="#">14x24</a>\'')); 627 $this->assertEquals('“<a href="#">14×24</a>”', wptexturize('"<a href="#">14x24</a>"')); 469 628 } 470 629 630 //WP Ticket #4116 631 function test_x_4116() { 632 $this->knownWPBug(4116); 633 $this->assertEquals('www.a4x3b.com', wptexturize("www.a4x3b.com")); 634 $this->assertEquals('http://www.youtube.com/watch?v=irWR7F0x2uU', wptexturize("http://www.youtube.com/watch?v=irWR7F0x2uU")); 635 } 636 471 637 function test_minutes_seconds() { 472 638 $this->assertEquals('9′', wptexturize('9\'')); 473 639 $this->assertEquals('9″', wptexturize("9\"")); … … 484 650 $this->assertEquals(' “Testing”', wptexturize(' "Testing"')); 485 651 $this->assertEquals('&“Testing”', wptexturize('&"Testing"')); 486 652 } 653 654 //WP Ticket #6969 655 function test_shortcode_skip() { 656 $this->assertEquals('[code lang="php"]$foo = \'bar\';[/code]', wptexturize('[code lang="php"]$foo = \'bar\';[/code]')); 657 } 658 487 659 } 488 660 489 661 class TestCleanUrl extends WPTestCase {