diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index ab3be7a76c..d71924fdd1 100644
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -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, '/');
diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php
index 305751001f..621d9bc806 100644
--- a/tests/phpunit/tests/formatting/WPTexturize.php
+++ b/tests/phpunit/tests/formatting/WPTexturize.php
@@ -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(
+ 'hello---',
+ 'hello—',
+ ),
+ array(
+ 'hello---',
+ 'hello—',
+ ),
+ array(
+ 'hello
---',
+ 'hello
—',
+ ),
+ array(
+ 'hello---',
+ 'hello—',
+ ),
+ array(
+ 'hello---
',
+ 'hello---
',
+ ),
+ array(
+ 'hello---',
+ 'hello---',
+ ),
+ array(
+ 'hello---',
+ 'hello---',
+ ),
+ array(
+ 'hello[/code]---',
+ 'hello[/code]—',
+ ),
+ array(
+ '[/code]hello---',
+ '[/code]hello—',
+ ),
+ array(
+ '[code]hello[/code]---',
+ '[code]hello[/code]—',
+ ),
+ array(
+ 'hello---[code]',
+ 'hello—[code]',
+ ),
+ array(
+ 'hello[code]---',
+ 'hello[code]---',
+ ),
+ array(
+ '[code]hello---',
+ '[code]hello---',
+ ),
+ array(
+ '[code]hello---',
+ '[code]hello---',
+ ),
+ );
+ }
}
\ No newline at end of file