diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index bbca0a6575..428014c369 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1828,7 +1828,7 @@ private static function dirAdd($base, $add) private static function toCSSArray($style) { - $style = trim(str_replace(["\r", "\n", ' '], '', $style), ';'); + $style = self::stripWhiteSpaceFromStyleString($style); $temp = explode(';', $style); $style = []; @@ -1857,6 +1857,11 @@ private static function toCSSArray($style) return $style; } + public static function stripWhiteSpaceFromStyleString($string) + { + return trim(str_replace(["\r", "\n", ' '], '', $string), ';'); + } + private static function boolean($value) { if (is_object($value)) { diff --git a/tests/PhpSpreadsheetTests/Reader/XlsxTest.php b/tests/PhpSpreadsheetTests/Reader/XlsxTest.php index 1180aacc33..f178e851bb 100644 --- a/tests/PhpSpreadsheetTests/Reader/XlsxTest.php +++ b/tests/PhpSpreadsheetTests/Reader/XlsxTest.php @@ -228,4 +228,29 @@ public function testLoadSaveWithEmptyDrawings() // Fake assert. The only thing we need is to ensure the file is loaded without exception $this->assertNotNull($excel); } + + /** + * Test if all whitespace is removed from a style definition string. + * This is needed to parse it into properties with the correct keys. + * + * @param $string + * @dataProvider providerStripsWhiteSpaceFromStyleString + */ + public function testStripsWhiteSpaceFromStyleString($string) + { + $string = Xlsx::stripWhiteSpaceFromStyleString($string); + $this->assertEquals(preg_match('/\s/', $string), 0); + } + + public function providerStripsWhiteSpaceFromStyleString() + { + return [ + ['position:absolute;margin-left:424.5pt;margin-top:169.5pt;width:67.5pt; + height:13.5pt;z-index:5;mso-wrap-style:tight'], + ['position:absolute;margin-left:424.5pt;margin-top:169.5pt;width:67.5pt; +height:13.5pt;z-index:5;mso-wrap-style:tight'], + ['position:absolute; margin-left:424.5pt; margin-top:169.5pt; width:67.5pt; + height:13.5pt;z-index:5;mso-wrap-style:tight'], + ]; + } }