diff --git a/controllers/PortableInfoboxParserTagController.class.php b/controllers/PortableInfoboxParserTagController.class.php index 994e90e..a984ed1 100644 --- a/controllers/PortableInfoboxParserTagController.class.php +++ b/controllers/PortableInfoboxParserTagController.class.php @@ -136,19 +136,9 @@ class PortableInfoboxParserTagController extends WikiaController { // Skip if the first marker is already at the top if ( strpos( $text, $firstMarker ) !== 0 ) { - $firstMarkerWithFollowingWhitespace = ''; - - $text = preg_replace_callback( - '/(' . $firstMarker . ')\s*/', - function ( $matches ) use ( &$firstMarkerWithFollowingWhitespace ) { - $firstMarkerWithFollowingWhitespace = $matches[0]; - return ''; - }, - $text, - 1 - ); - - $text = $firstMarkerWithFollowingWhitespace . $text; + // Remove first marker and the following whitespace + $text = preg_replace( '/' . $firstMarker . '\s*/', '', $text, 1 ); + $text = $firstMarker . ' ' . $text; } } } diff --git a/tests/PortableInfoboxParserTagControllerTest.php b/tests/PortableInfoboxParserTagControllerTest.php index b279779..c5f308c 100644 --- a/tests/PortableInfoboxParserTagControllerTest.php +++ b/tests/PortableInfoboxParserTagControllerTest.php @@ -276,8 +276,8 @@ class PortableInfoboxParserTagControllerTest extends WikiaBaseTest { 'infobox-1' => '1' ], 'text' => 'nospaceinfobox-1', - 'expected' => 'infobox-1nospace', - 'message' => 'no space between elements' + 'expected' => 'infobox-1 nospace', + 'message' => 'no space between input elements' ], [ 'markers' => [ @@ -290,8 +290,7 @@ class PortableInfoboxParserTagControllerTest extends WikiaBaseTest { more text infobox-2 and some more', - 'expected' => 'infobox-1 - some text + 'expected' => 'infobox-1 some text some more more text infobox-2