Ticket #4539: formatting_latest_fixes_all.diff
File formatting_latest_fixes_all.diff, 8.9 KB (added by , 14 years ago) |
---|
-
wp-testcase/test_includes_formatting.php
386 386 $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); 387 387 } 388 388 389 //WP Ticket #4539 390 function test_basic_quotes() { 391 $this->assertEquals('test’s', wptexturize('test\'s')); 392 $this->assertEquals('test’s', wptexturize('test\'s')); 393 394 $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); 395 $this->assertEquals('“quoted”', wptexturize('"quoted"')); 396 397 $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); 398 $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); 399 400 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); 401 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); 402 403 $this->assertEquals('‘test’s quoted’', wptexturize('\'test\'s quoted\'')); 404 $this->assertEquals('“test’s quoted”', wptexturize('"test\'s quoted"')); 405 } 406 407 //WP Ticket #4539 389 408 function test_quotes() { 390 $this->knownWPBug(4539);391 409 $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); 392 410 $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>"')); 393 $this->assertEquals('Here is “<a href="http://example.com">a test with a link and a period 411 $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>".')); 394 412 $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.')); 395 413 $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"')); 396 414 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.')); 397 415 $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.')); 398 416 $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.')); 399 $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.'));417 $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.')); 400 418 $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>".')); 401 419 $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.')); 402 420 $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); 403 421 $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.')); 404 422 } 405 423 406 //WP Ticket # 1258424 //WP Ticket #4539 407 425 function test_quotes_before_s() { 408 $this->knownWPBug(4539);409 426 $this->assertEquals('test’s', wptexturize("test's")); 410 427 $this->assertEquals('‘test’s', wptexturize("'test's")); 411 428 $this->assertEquals('‘test’s’', wptexturize("'test's'")); … … 415 432 416 433 //WP Ticket #4539 417 434 function test_quotes_before_numbers() { 418 $this->knownWPBug(4539);419 435 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 436 $this->assertEquals('Class of ’99’s', wptexturize("Class of '99's")); 420 437 $this->assertEquals('‘Class of ’99’', wptexturize("'Class of '99'")); 438 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'")); 439 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'")); 440 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); 441 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); 421 442 } 422 443 444 function test_quotes_after_numbers() { 445 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 446 } 447 448 //WP Ticket #15241 423 449 function test_other_html() { 424 $this-> knownWPBug(15241);425 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize( "'<strong>Quoted Text</strong>',"));450 $this->assertEquals('‘<strong>', wptexturize("'<strong>")); 451 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize('\'<strong>Quoted Text</strong>\',')); 426 452 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); 427 453 } 454 455 function test_x() { 456 $this->assertEquals('14×24', wptexturize("14x24")); 457 } 458 459 function test_minutes_seconds() { 460 $this->assertEquals('9′', wptexturize('9\'')); 461 $this->assertEquals('9″', wptexturize("9\"")); 462 463 $this->assertEquals('a 9′ b', wptexturize('a 9\' b')); 464 $this->assertEquals('a 9″ b', wptexturize("a 9\" b")); 465 466 $this->assertEquals('“a 9′ b”', wptexturize('"a 9\' b"')); 467 $this->assertEquals('‘a 9″ b’', wptexturize("'a 9\" b'")); 468 } 428 469 } 429 470 430 471 class TestCleanUrl extends WPTestCase { -
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'); 61 59 $dynamic_map = array( 60 '/\'(\d)/' => '’$1', // '99 61 62 '/\'([^\']*)\'([^\']*)\'/' => '‘$1’$2’', // 'test's' 63 64 '/\'([^\']*)\'/' => '‘$1’', // 'asd' 65 '/"([^"]*)"/' => $opening_quote . '$1' . $closing_quote, // "qwe" 66 67 '/(\w)\'(\w)/' => '$1’$2', // test's 68 69 '/(\d)"/' => '$1″', // 9" -> 9″ 70 '/(\d)\'/' => '$1′', // 9' -> 9′ 71 72 '/\b(\d+)x(\d+)\b/' => '$1×$2' // 10. 97x34 => 97×34 73 ); 74 75 $dynamic_characters = array_keys($dynamic_map); 76 $dynamic_replacements = array_values($dynamic_map); 77 62 78 $static_setup = true; 63 79 } 64 80 … … 69 85 70 86 $no_texturize_tags_stack = array(); 71 87 $no_texturize_shortcodes_stack = array(); 88 89 $single_quote_state = '‘'; 90 $doube_quote_state = $opening_quote; 72 91 73 92 for ( $i = 0; $i < $stop; $i++ ) { 74 93 $curl = $textarr[$i]; … … 80 99 $curl = str_replace($static_characters, $static_replacements, $curl); 81 100 // regular expressions 82 101 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 102 // quotes that span multiple tags & shortcodes 103 while (($pos = strpos($curl, '\'')) !== FALSE) { 104 $curl = preg_replace('/\'/', $single_quote_state, $curl); 105 $single_quote_state = (($single_quote_state == '‘') ? '’' : '‘'); 106 } 107 while (($pos = strpos($curl, '"')) !== FALSE) { 108 $curl = preg_replace('/"/', $doube_quote_state, $curl); 109 $doube_quote_state = (($doube_quote_state == $opening_quote) ? $closing_quote : $opening_quote); 110 } 83 111 } elseif (!empty($curl)) { 84 112 /* 85 113 * Only call _wptexturize_pushpop_element if first char is correct