| 1 | Index: wp-testcase/test_includes_formatting.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-testcase/test_includes_formatting.php (revision 315) |
|---|
| 4 | +++ wp-testcase/test_includes_formatting.php (working copy) |
|---|
| 5 | @@ -386,26 +386,43 @@ |
|---|
| 6 | $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | + //WP Ticket #4539 |
|---|
| 10 | + function test_basic_quotes() { |
|---|
| 11 | + $this->assertEquals('test’s', wptexturize('test\'s')); |
|---|
| 12 | + $this->assertEquals('test’s', wptexturize('test\'s')); |
|---|
| 13 | + |
|---|
| 14 | + $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); |
|---|
| 15 | + $this->assertEquals('“quoted”', wptexturize('"quoted"')); |
|---|
| 16 | + |
|---|
| 17 | + $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); |
|---|
| 18 | + $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); |
|---|
| 19 | + |
|---|
| 20 | + $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); |
|---|
| 21 | + $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); |
|---|
| 22 | + |
|---|
| 23 | + $this->assertEquals('‘test’s quoted’', wptexturize('\'test\'s quoted\'')); |
|---|
| 24 | + $this->assertEquals('“test’s quoted”', wptexturize('"test\'s quoted"')); |
|---|
| 25 | + } |
|---|
| 26 | + |
|---|
| 27 | + //WP Ticket #4539 |
|---|
| 28 | function test_quotes() { |
|---|
| 29 | - $this->knownWPBug(4539); |
|---|
| 30 | $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); |
|---|
| 31 | $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>"')); |
|---|
| 32 | - $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>".')); |
|---|
| 33 | + $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>".')); |
|---|
| 34 | $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.')); |
|---|
| 35 | $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"')); |
|---|
| 36 | $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.')); |
|---|
| 37 | $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.')); |
|---|
| 38 | $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.')); |
|---|
| 39 | - $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.')); |
|---|
| 40 | + $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.')); |
|---|
| 41 | $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>".')); |
|---|
| 42 | $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.')); |
|---|
| 43 | $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); |
|---|
| 44 | $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.')); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | - //WP Ticket #1258 |
|---|
| 48 | + //WP Ticket #4539 |
|---|
| 49 | function test_quotes_before_s() { |
|---|
| 50 | - $this->knownWPBug(4539); |
|---|
| 51 | $this->assertEquals('test’s', wptexturize("test's")); |
|---|
| 52 | $this->assertEquals('‘test’s', wptexturize("'test's")); |
|---|
| 53 | $this->assertEquals('‘test’s’', wptexturize("'test's'")); |
|---|
| 54 | @@ -415,16 +432,40 @@ |
|---|
| 55 | |
|---|
| 56 | //WP Ticket #4539 |
|---|
| 57 | function test_quotes_before_numbers() { |
|---|
| 58 | - $this->knownWPBug(4539); |
|---|
| 59 | $this->assertEquals('Class of ’99', wptexturize("Class of '99")); |
|---|
| 60 | + $this->assertEquals('Class of ’99’s', wptexturize("Class of '99's")); |
|---|
| 61 | $this->assertEquals('‘Class of ’99’', wptexturize("'Class of '99'")); |
|---|
| 62 | + $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'")); |
|---|
| 63 | + $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'")); |
|---|
| 64 | + $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); |
|---|
| 65 | + $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | + function test_quotes_after_numbers() { |
|---|
| 69 | + $this->assertEquals('Class of ’99', wptexturize("Class of '99")); |
|---|
| 70 | + } |
|---|
| 71 | + |
|---|
| 72 | + //WP Ticket #15241 |
|---|
| 73 | function test_other_html() { |
|---|
| 74 | - $this->knownWPBug(15241); |
|---|
| 75 | - $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',")); |
|---|
| 76 | + $this->assertEquals('‘<strong>', wptexturize("'<strong>")); |
|---|
| 77 | + $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize('\'<strong>Quoted Text</strong>\',')); |
|---|
| 78 | $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); |
|---|
| 79 | } |
|---|
| 80 | + |
|---|
| 81 | + function test_x() { |
|---|
| 82 | + $this->assertEquals('14×24', wptexturize("14x24")); |
|---|
| 83 | + } |
|---|
| 84 | + |
|---|
| 85 | + function test_minutes_seconds() { |
|---|
| 86 | + $this->assertEquals('9′', wptexturize('9\'')); |
|---|
| 87 | + $this->assertEquals('9″', wptexturize("9\"")); |
|---|
| 88 | + |
|---|
| 89 | + $this->assertEquals('a 9′ b', wptexturize('a 9\' b')); |
|---|
| 90 | + $this->assertEquals('a 9″ b', wptexturize("a 9\" b")); |
|---|
| 91 | + |
|---|
| 92 | + $this->assertEquals('“a 9′ b”', wptexturize('"a 9\' b"')); |
|---|
| 93 | + $this->assertEquals('‘a 9″ b’', wptexturize("'a 9\" b'")); |
|---|
| 94 | + } |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | class TestCleanUrl extends WPTestCase { |
|---|
| 98 | Index: wordpress/wp-includes/formatting.php |
|---|
| 99 | =================================================================== |
|---|
| 100 | --- wordpress/wp-includes/formatting.php (revision 16231) |
|---|
| 101 | +++ wordpress/wp-includes/formatting.php (working copy) |
|---|
| 102 | @@ -56,9 +56,25 @@ |
|---|
| 103 | $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney); |
|---|
| 104 | $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace); |
|---|
| 105 | |
|---|
| 106 | - $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/'); |
|---|
| 107 | - $dynamic_replacements = array('’$1','’$1', '$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2'); |
|---|
| 108 | - |
|---|
| 109 | + $dynamic_map = array( |
|---|
| 110 | + '/\'(\d)/' => '’$1', // '99 |
|---|
| 111 | + |
|---|
| 112 | + '/\'([^\']*)\'([^\']*)\'/' => '‘$1’$2’', // 'test's' |
|---|
| 113 | + |
|---|
| 114 | + '/\'([^\']*)\'/' => '‘$1’', // 'asd' |
|---|
| 115 | + '/"([^"]*)"/' => $opening_quote . '$1' . $closing_quote, // "qwe" |
|---|
| 116 | + |
|---|
| 117 | + '/(\w)\'(\w)/' => '$1’$2', // test's |
|---|
| 118 | + |
|---|
| 119 | + '/(\d)"/' => '$1″', // 9" -> 9″ |
|---|
| 120 | + '/(\d)\'/' => '$1′', // 9' -> 9′ |
|---|
| 121 | + |
|---|
| 122 | + '/\b(\d+)x(\d+)\b/' => '$1×$2' // 10. 97x34 => 97×34 |
|---|
| 123 | + ); |
|---|
| 124 | + |
|---|
| 125 | + $dynamic_characters = array_keys($dynamic_map); |
|---|
| 126 | + $dynamic_replacements = array_values($dynamic_map); |
|---|
| 127 | + |
|---|
| 128 | $static_setup = true; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | @@ -69,6 +85,9 @@ |
|---|
| 132 | |
|---|
| 133 | $no_texturize_tags_stack = array(); |
|---|
| 134 | $no_texturize_shortcodes_stack = array(); |
|---|
| 135 | + |
|---|
| 136 | + $single_quote_state = '‘'; |
|---|
| 137 | + $doube_quote_state = $opening_quote; |
|---|
| 138 | |
|---|
| 139 | for ( $i = 0; $i < $stop; $i++ ) { |
|---|
| 140 | $curl = $textarr[$i]; |
|---|
| 141 | @@ -80,6 +99,15 @@ |
|---|
| 142 | $curl = str_replace($static_characters, $static_replacements, $curl); |
|---|
| 143 | // regular expressions |
|---|
| 144 | $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); |
|---|
| 145 | + // quotes that span multiple tags & shortcodes |
|---|
| 146 | + while (($pos = strpos($curl, '\'')) !== FALSE) { |
|---|
| 147 | + $curl = preg_replace('/\'/', $single_quote_state, $curl); |
|---|
| 148 | + $single_quote_state = (($single_quote_state == '‘') ? '’' : '‘'); |
|---|
| 149 | + } |
|---|
| 150 | + while (($pos = strpos($curl, '"')) !== FALSE) { |
|---|
| 151 | + $curl = preg_replace('/"/', $doube_quote_state, $curl); |
|---|
| 152 | + $doube_quote_state = (($doube_quote_state == $opening_quote) ? $closing_quote : $opening_quote); |
|---|
| 153 | + } |
|---|
| 154 | } elseif (!empty($curl)) { |
|---|
| 155 | /* |
|---|
| 156 | * Only call _wptexturize_pushpop_element if first char is correct |
|---|