Ticket #4539: dev-snapshot-2010-11-22.php.diff
File dev-snapshot-2010-11-22.php.diff, 18.0 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 '/([\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 } 105 81 106 // regular expressions 82 107 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 108 109 // Quotes that span across multiple tags & shortcodes 110 // Dynamic regexps above ensure that there is at most 1 quote left in the string. 111 // Otherwise, the less efficient preg_replace() within a while loop would be required. 112 if ( strpos( $curl, '\'' ) !== false ) { 113 $curl = str_replace( '\'', $single_quote_state, $curl); 114 $single_quote_state = ( ( '‘' == $single_quote_state ) ? '’' : '‘' ); 115 } 116 if ( strpos($curl, '"' ) !== false ) { 117 $curl = str_replace( '"', $double_quote_state, $curl); 118 $double_quote_state = ( $opening_quote == $double_quote_state ) ? $closing_quote : $opening_quote; 119 } 120 // stats for quotes after tags above 121 $text_node_count++; 122 $whitespace_before_last_tag = ( preg_match('/\s$/', $curl) > 0 ); 83 123 } elseif (!empty($curl)) { 84 124 /* 85 125 * Only call _wptexturize_pushpop_element if first char is correct -
wp-testcase/test_includes_formatting.php
371 371 372 372 $invalid_nest = '<pre></code>"baba"</pre>'; 373 373 $this->assertEquals($invalid_nest, wptexturize($invalid_nest)); 374 } 374 375 376 //WP Ticket #8912, #10033 377 function test_skip_html_comments() { 378 $this->assertEquals('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>')); 379 380 $html = '<!--[if !IE]>-->' . "\n"; 381 $html .= '<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/_nkZ3eHeXlc" width="320" height="260">' . "\n"; 382 $html .= '<!--<![endif]-->' . "\n"; 383 $this->assertEquals($html, wptexturize($html)); 384 385 $html = '<!--[if !IE]>-->' . "\n"; 386 $html .= '</object>' . "\n"; 387 $html .= '<!--<![endif]-->' . "\n"; 388 $this->assertEquals($html, wptexturize($html)); 375 389 } 376 390 377 391 //WP Ticket #1418 378 392 function test_bracketed_quotes_1418() { 379 393 $this->assertEquals('(“test”)', wptexturize('("test")')); … … 385 399 function test_bracketed_quotes_3810() { 386 400 $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); 387 401 } 388 402 389 403 //WP Ticket #4539 390 404 function test_basic_quotes() { 405 $this->assertNotEquals('‘’', wptexturize("''")); // this does not work as expected due to a static replacement 406 $this->assertEquals('“”', wptexturize('""')); 407 $this->assertEquals('“”', wptexturize("``''")); // this is what causes '' to fail 408 $this->assertEquals('‘ ’', wptexturize("' '")); 409 $this->assertEquals('“ ”', wptexturize('" "')); 410 $this->assertEquals('‘<img src="">’', wptexturize('\'<img src="">\'')); 411 $this->assertEquals('“<img src="">”', wptexturize('"<img src="">"')); 412 $this->assertEquals('Peter’s photo: ‘<img src="">’', wptexturize('Peter\'s photo: \'<img src="">\'')); 413 $this->assertEquals('Peter’s photo: “<img src="">”', wptexturize('Peter\'s photo: "<img src="">"')); 414 391 415 $this->assertEquals('test’s', wptexturize('test\'s')); 392 416 $this->assertEquals('test’s', wptexturize('test\'s')); 393 417 394 418 $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); 395 419 $this->assertEquals('“quoted”', wptexturize('"quoted"')); 420 $this->assertEquals('‘quoted’s’', wptexturize('\'quoted\'s\'')); 421 $this->assertEquals('“quoted’s”', wptexturize('"quoted\'s"')); 396 422 397 423 $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); 398 424 $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); 425 $this->assertEquals('["quoted"]', wptexturize('["quoted"]')); // shortcode 426 $this->assertEquals('<"quoted">', wptexturize('<"quoted">')); // tag 427 $this->assertEquals('(‘quoted’s’)', wptexturize('(\'quoted\'s\')')); 428 $this->assertEquals('{“quoted’s”}', wptexturize('{"quoted\'s"}')); 429 $this->assertEquals('["quoted\'s"]', wptexturize('["quoted\'s"]')); // shortcode 430 $this->assertEquals('<"quoted\'s">', wptexturize('<"quoted\'s">')); // tag 399 431 400 432 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); 401 433 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); 434 $this->assertEquals('“qu[ot]ed”', wptexturize('"qu[ot]ed"')); 435 $this->assertEquals('“qu<ot>ed”', wptexturize('"qu<ot>ed"')); 436 $this->assertEquals('‘qu(ot)ed’s’', wptexturize('\'qu(ot)ed\'s\'')); 437 $this->assertEquals('“qu{ot}ed’s”', wptexturize('"qu{ot}ed\'s"')); 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)’s’', wptexturize('\'qu(ot)\'s\'')); 441 $this->assertEquals('“qu{ot}’s”', wptexturize('"qu{ot}\'s"')); 442 $this->assertEquals('“qu[ot]’s”', wptexturize('"qu[ot]\'s"')); 443 $this->assertEquals('“qu<ot>’s”', wptexturize('"qu<ot>\'s"')); 402 444 403 445 $this->assertEquals('‘test’s quoted’', wptexturize('\'test\'s quoted\'')); 404 446 $this->assertEquals('“test’s quoted”', wptexturize('"test\'s quoted"')); 405 447 } 406 448 449 //WP Ticket #4539 450 function test_nested_quotes() { 451 $this->assertEquals('“This is a ‘nested quote’.”', wptexturize('"This is a \'nested quote\'."')); 452 $this->assertEquals('‘This is a “nested quote”.’', wptexturize('\'This is a "nested quote".\'')); 453 $this->assertEquals('“These are some ‘nested’ ‘quotes’.”', wptexturize('"These are some \'nested\' \'quotes\'."')); 454 $this->assertEquals('‘These are some “nested” “quotes”.’', wptexturize('\'These are some "nested" "quotes".\'')); 455 } 456 407 457 //WP Tickets #4539, #15241 408 458 function test_full_sentences_with_unmatched_single_quotes() { 409 459 $this->assertEquals( 410 460 'That means every moment you’re working on something without it being in the public it’s actually dying.', 411 461 wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") 412 462 ); 463 $this->assertEquals( 464 '‘That means every moment you’re working on something without it being in the public it’s actually dying.’', 465 wptexturize("'That means every moment you're working on something without it being in the public it's actually dying.'") 466 ); 467 $this->assertEquals( 468 '“That means every moment you’re working on something without it being in the public it’s actually dying.”', 469 wptexturize("\"That means every moment you're working on something without it being in the public it's actually dying.\"") 470 ); 471 $this->assertEquals( 472 'That means every moment you’re working on ‘something’ without it being in the public it’s actually dying.', 473 wptexturize("That means every moment you're working on 'something' without it being in the public it's actually dying.") 474 ); 475 $this->assertEquals( 476 'That means every moment you’re working on “something” without it being in the public it’s actually dying.', 477 wptexturize("That means every moment you're working on \"something\" without it being in the public it's actually dying.") 478 ); 413 479 } 414 480 415 //WP Ticket #4539481 //WP Tickets #4539, #10606 416 482 function test_quotes() { 417 483 $this->knownWPBug(4539); 418 484 $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); 419 485 $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>"')); 486 $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> "')); 487 $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 488 $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 489 $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 490 $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 492 $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 493 $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 494 $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.')); 495 $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 496 $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.')); 497 $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>" .')); 498 $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 499 $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); 430 500 $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 501 } … … 451 521 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); 452 522 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); 453 523 } 454 455 function test_quotes_after_numbers() { 456 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 457 } 458 524 459 525 //WP Ticket #15241 460 526 function test_other_html() { 461 527 $this->knownWPBug(15241); 462 528 $this->assertEquals('‘<strong>', wptexturize("'<strong>")); 529 $this->assertEquals('“<strong>', wptexturize('"<strong>')); 530 $this->assertEquals('‘<strong></strong>’', wptexturize("'<strong></strong>'")); 531 $this->assertEquals('“<strong></strong>”', wptexturize('"<strong></strong>"')); 463 532 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',")); 464 533 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); 465 534 } 466 535 536 //WP Ticket #15241 537 function test_many_single_quotes() { 538 $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.")); 539 } 540 541 //WP Ticket #1258 542 function test_enumeration() { 543 $this->assertEquals("‘products’, ‘services’", wptexturize("'products', 'services'")); 544 $this->assertEquals("‘hello’, ‘world’, ’tis", wptexturize("'hello', 'world', 'tis")); 545 $this->assertEquals("‘hello’, ‘world’, ’tis ", wptexturize("'hello', 'world', 'tis ")); 546 } 547 548 //WP Ticket #11275 549 function test_quoting() { 550 $this->assertEquals('She said—“No!”', wptexturize('She said—"No!"')); 551 $this->assertEquals('She said — “No!”', wptexturize('She said — "No!"')); 552 $this->assertEquals('She said—“<a href="#">No!</a>”', wptexturize('She said—"<a href="#">No!</a>"')); 553 $this->assertEquals('She said—‘<a href="#">It’s Peter’s!</a>’', wptexturize('She said—\'<a href="#">It\'s Peter\'s!</a>\'')); 554 $this->assertEquals('She said—“<a href="#">It’s Peter’s!</a>”', wptexturize('She said—"<a href="#">It\'s Peter\'s!</a>"')); 555 } 556 557 //WP Ticket #15444 558 function test_tag_followed_by_quote() { 559 $this->knownWPBug(15444); 560 $this->assertEquals('<a href="#">Jim</a>’s red bike.', wptexturize('<a href="#">Jim</a>\'s red bike.')); 561 $this->assertEquals('‘<a href="#">Jim</a>’s red bike.’', wptexturize('\'<a href="#">Jim</a>\'s red bike.\'')); 562 $this->assertEquals('“<a href="#">Jim</a>’s red bike.”', wptexturize('"<a href="#">Jim</a>\'s red bike."')); 563 $this->assertEquals('<a href="#">Jim</a>’s ‘red bike.’', wptexturize('<a href="#">Jim</a>\'s \'red bike.\'')); 564 $this->assertEquals('<a href="#">Jim</a>’s “red bike.”', wptexturize('<a href="#">Jim</a>\'s "red bike."')); 565 $this->assertEquals('<a href="#">Jim</a>’s ‘<a href="#">red bike</a>.’', wptexturize('<a href="#">Jim</a>\'s \'<a href="#">red bike</a>.\'')); 566 $this->assertEquals('<a href="#">Jim</a>’s “<a href="#">red bike</a>.”', wptexturize('<a href="#">Jim</a>\'s "<a href="#">red bike</a>."')); 567 } 568 467 569 function test_x() { 468 570 $this->assertEquals('14×24', wptexturize("14x24")); 571 $this->assertEquals('‘14×24’', wptexturize("'14x24'")); 572 $this->assertEquals('“14×24”', wptexturize('"14x24"')); 573 $this->assertEquals('‘<a href="#">14×24</a>’', wptexturize('\'<a href="#">14x24</a>\'')); 574 $this->assertEquals('“<a href="#">14×24</a>”', wptexturize('"<a href="#">14x24</a>"')); 469 575 } 470 576 577 //WP Ticket #4116 578 function test_x_4116() { 579 $this->knownWPBug(4116); 580 $this->assertEquals('www.a4x3b.com', wptexturize("www.a4x3b.com")); 581 $this->assertEquals('http://www.youtube.com/watch?v=irWR7F0x2uU', wptexturize("http://www.youtube.com/watch?v=irWR7F0x2uU")); 582 } 583 471 584 function test_minutes_seconds() { 472 585 $this->assertEquals('9′', wptexturize('9\'')); 473 586 $this->assertEquals('9″', wptexturize("9\"")); … … 484 597 $this->assertEquals(' “Testing”', wptexturize(' "Testing"')); 485 598 $this->assertEquals('&“Testing”', wptexturize('&"Testing"')); 486 599 } 600 601 //WP Ticket #6969 602 function test_shortcode_skip() { 603 $this->assertEquals('[code lang="php"]$foo = \'bar\';[/code]', wptexturize('[code lang="php"]$foo = \'bar\';[/code]')); 604 } 487 605 } 488 606 489 607 class TestCleanUrl extends WPTestCase {