diff --git a/controllers/PortableInfoboxParserTagController.class.php b/controllers/PortableInfoboxParserTagController.class.php index 75651f0..df84855 100644 --- a/controllers/PortableInfoboxParserTagController.class.php +++ b/controllers/PortableInfoboxParserTagController.class.php @@ -102,10 +102,12 @@ class PortableInfoboxParserTagController extends WikiaController { private function getThemeWithDefault( $params, PPFrame $frame ) { $value = isset( $params[ 'theme-source' ] ) ? $frame->getArgument( $params[ 'theme-source' ] ) : false; - return self::INFOBOX_THEME_PREFIX . $this->getThemePrefix( $params, $value ); + $themeName = $this->getThemeName( $params, $value ); + //make sure no whitespaces, prevents side effects + return self::INFOBOX_THEME_PREFIX . preg_replace( '|\s+|s', '-', $themeName ); } - private function getThemePrefix( $params, $value ) { + private function getThemeName( $params, $value ) { return !empty( $value ) ? $value : // default logic ( isset( $params[ 'theme' ] ) ? $params[ 'theme' ] : self::DEFAULT_THEME_NAME ); diff --git a/tests/PortableInfoboxParserTagControllerTest.php b/tests/PortableInfoboxParserTagControllerTest.php index 7cd276c..9fb8f96 100644 --- a/tests/PortableInfoboxParserTagControllerTest.php +++ b/tests/PortableInfoboxParserTagControllerTest.php @@ -94,4 +94,34 @@ class PortableInfoboxParserTagControllerTest extends WikiaBaseTest { PortableInfoboxParserTagController::INFOBOX_THEME_PREFIX . PortableInfoboxParserTagController::DEFAULT_THEME_NAME ) ); } + + public function testWhiteSpacedThemeInfobox() { + $text = 'test'; + $defaultTheme = 'test test'; + $expectedName = 'test-test'; + + $marker = $this->controller->renderInfobox( $text, [ 'theme' => $defaultTheme ], $this->parser, + $this->parser->getPreprocessor()->newFrame() )[ 0 ]; + $output = $this->controller->replaceMarkers( $marker ); + + $this->assertTrue( $this->checkClassName( + $output, + PortableInfoboxParserTagController::INFOBOX_THEME_PREFIX . $expectedName + ) ); + } + + public function testMultiWhiteSpacedThemeInfobox() { + $text = 'test'; + $defaultTheme = "test test\n test\ttest"; + $expectedName = 'test-test-test-test'; + + $marker = $this->controller->renderInfobox( $text, [ 'theme' => $defaultTheme ], $this->parser, + $this->parser->getPreprocessor()->newFrame() )[ 0 ]; + $output = $this->controller->replaceMarkers( $marker ); + + $this->assertTrue( $this->checkClassName( + $output, + PortableInfoboxParserTagController::INFOBOX_THEME_PREFIX . $expectedName + ) ); + } }