diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 91690d8f4b..659db978d8 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -233,6 +233,10 @@ function wptexturize( $text, $reset = false ) { continue; } else { // This is an HTML element delimiter. + + // Replace each & with & unless it already looks like an entity. + $curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl ); + _wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags ); } diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 475a4755fc..4d7caf3d06 100644 --- a/tests/phpunit/tests/formatting/WPTexturize.php +++ b/tests/phpunit/tests/formatting/WPTexturize.php @@ -10,14 +10,14 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { } function test_disable() { - $this->assertEquals('
---
', wptexturize('
---
')); - $this->assertEquals('
--
', wptexturize('
--
')); + $this->assertEquals('
---&
', wptexturize('
---&
')); + $this->assertEquals('
--&
', wptexturize('
--&
')); - $this->assertEquals( '---', wptexturize( '---' ) ); - $this->assertEquals( '---', wptexturize( '---' ) ); - $this->assertEquals( '', wptexturize( '' ) ); - $this->assertEquals( '', wptexturize( '' ) ); - $this->assertEquals( '---', wptexturize( '---' ) ); + $this->assertEquals( '---&', wptexturize( '---&' ) ); + $this->assertEquals( '---&', wptexturize( '---&' ) ); + $this->assertEquals( '', wptexturize( '' ) ); + $this->assertEquals( '', wptexturize( '' ) ); + $this->assertEquals( '---&', wptexturize( '---&' ) ); $this->assertEquals('href="baba" “baba”', wptexturize('href="baba" "baba"')); @@ -1268,11 +1268,15 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( '[ photos by this guy & that guy ]', - '[ photos by this guy & that guy ]', + '[ photos by this guy & that guy ]', ), array( '[photos by this guy & that guy ]', - '[photos by this guy & that guy ]', + '[photos by this guy & that guy ]', + ), + array( + '& ', + '& ' ), array( '[gallery ...]',