Add unit tests to confirm that `---` is properly converted to `—` by `wptexturize()` where appropriate.

Props miqrogroove.
Fixes #28483.


git-svn-id: https://develop.svn.wordpress.org/trunk@28763 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-17 18:06:12 +00:00
parent 14f3b15d69
commit 6f658551d6
2 changed files with 75 additions and 2 deletions

View File

@ -274,6 +274,8 @@ function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $openi
array_push($stack, $matches[1]);
}
} elseif ( 0 == count( $stack ) ) {
// Stack is empty. Just stop.
} else {
// Closing? Check $text+2 against disabled elements
$c = preg_quote($closing, '/');

View File

@ -1178,8 +1178,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
'[[[...]]]…[[[/...]]]',
),
array(
'[[code]...[/code]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[/code] is ambiguous unless we run the entire shortcode regexp.
'[[code]…[/code]...', // Same behavior as 3.9 due to buggy logic in _wptexturize_pushpop_element(). See ticket #28483.
'[[code]...[/code]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[code] is ambiguous unless we run the entire shortcode regexp.
'[[code]…[/code]…',
),
array(
'[code]...[/code]]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [/code]] is ambiguous unless we run the entire shortcode regexp.
@ -1585,4 +1585,75 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
),
);
}
/**
* Extra sanity checks for _wptexturize_pushpop_element()
*
* @ticket 28483
* @dataProvider data_quotes_and_dashes
*/
function test_element_stack( $input, $output ) {
return $this->assertEquals( $output, wptexturize( $input ) );
}
function data_element_stack() {
return array(
array(
'<span>hello</code>---</span>',
'<span>hello</code>&#8212;</span>',
),
array(
'</code>hello<span>---</span>',
'</code>hello<span>&#8212;</span>',
),
array(
'<code>hello</code>---</span>',
'<code>hello</code>&#8212;</span>',
),
array(
'<span>hello</span>---<code>',
'<span>hello</span>&#8212;<code>',
),
array(
'<span>hello<code>---</span>',
'<span>hello<code>---</span>',
),
array(
'<code>hello<span>---</span>',
'<code>hello<span>---</span>',
),
array(
'<code>hello</span>---</span>',
'<code>hello</span>---</span>',
),
array(
'<span>hello[/code]---</span>',
'<span>hello[/code]&#8212;</span>',
),
array(
'[/code]hello<span>---</span>',
'[/code]hello<span>&#8212;</span>',
),
array(
'[code]hello[/code]---</span>',
'[code]hello[/code]&#8212;</span>',
),
array(
'<span>hello</span>---[code]',
'<span>hello</span>&#8212;[code]',
),
array(
'<span>hello[code]---</span>',
'<span>hello[code]---</span>',
),
array(
'[code]hello<span>---</span>',
'[code]hello<span>---</span>',
),
array(
'[code]hello</span>---</span>',
'[code]hello</span>---</span>',
),
);
}
}