Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace spaces from style string #1348

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

### Added

- Improved the ARABIC function to also hande short-hand roman numerals

### Fixed

- Fix ROUNDUP and ROUNDDOWN for floating-point rounding error [#1404](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1404)

## [1.11.0] - 2020-03-02
PowerKiKi marked this conversation as resolved.
Show resolved Hide resolved

### Added

- Added support for the BASE function
- Added support for the ARABIC function
- Conditionals - Extend Support for (NOT)CONTAINSBLANKS [#1278](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1278)

### Fixed
Expand All @@ -33,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Fix active cell when freeze pane is used [#1323](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1323)
- Fix XLSX file loading with autofilter containing '$' [#1326](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1326)
- PHPDoc - Use `@return $this` for fluent methods [#1362](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1362)
- Fix loading styles from vmlDrawings when containing whitespace [#1347](/~https://github.com/PHPOffice/PhpSpreadsheet/issues/1347)

## [1.10.1] - 2019-12-02

Expand Down
7 changes: 6 additions & 1 deletion src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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)) {
Expand Down
25 changes: 25 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/XlsxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}