Skip to content

Commit

Permalink
[BUGFIX] Fix mapping width/height when decimal is used (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
uzegonemad authored Feb 26, 2020
1 parent 2d4b21d commit 1dac6a0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
([#773](https://github.com/MyIntervals/emogrifier/pull/773))

### Fixed
- Fix mapping width/height when decimal is used
([#845](https://github.com/MyIntervals/emogrifier/pull/845))
- Actually use the specified PHP version on GitHub actions
([#836](https://github.com/MyIntervals/emogrifier/pull/836))
- Support `ci:php:lint` on Windows
Expand Down
2 changes: 1 addition & 1 deletion src/HtmlProcessor/CssToAttributeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private function mapBackgroundProperty(\DOMElement $node, string $value)
private function mapWidthOrHeightProperty(\DOMElement $node, string $value, string $property)
{
// only parse values in px and %, but not values like "auto"
if (!\preg_match('/^(\\d+)(px|%)$/', $value)) {
if (!\preg_match('/^(\\d+)(\\.(\\d+))?(px|%)$/', $value)) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/HtmlProcessor/CssToAttributeConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ public function matchingCssToHtmlMappingDataProvider(): array
'background => bgcolor' => ['<p style="background: red top;">Bonjour</p>', 'bgcolor="red"'],
'width with px' => ['<p style="width: 100px;">Hi</p>', 'width="100"'],
'width with %' => ['<p style="width: 50%;">Hi</p>', 'width="50%"'],
'width with decimal %' => ['<p style="width: 50.5%;">Hi</p>', 'width="50.5%"'],
'height with px' => ['<p style="height: 100px;">Hi</p>', 'height="100"'],
'height with %' => ['<p style="height: 50%;">Hi</p>', 'height="50%"'],
'height with decimal %' => ['<p style="height: 50.5%;">Hi</p>', 'height="50.5%"'],
'img.margin: 0 auto (horizontal centering) => align=center' => [
'<img style="margin: 0 auto;">',
'align="center"',
Expand Down

0 comments on commit 1dac6a0

Please sign in to comment.