Skip to content

Commit 9ad776b

Browse files
authored
[BUGFIX] Use safe preg functions in Size (#1380)
Also use typesafe comparisons in the affected line. Part of #1168
1 parent c1929d4 commit 9ad776b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Please also have a look at our
1818

1919
### Fixed
2020

21-
- Use typesafe versions of PHP functions (#1379)
21+
- Use typesafe versions of PHP functions (#1379, #1380)
2222

2323
### Documentation
2424

src/Value/Size.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
1010
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1111

12+
use function Safe\preg_match;
13+
use function Safe\preg_replace;
14+
1215
/**
1316
* A `Size` consists of a numeric `size` value and a unit.
1417
*/
@@ -202,9 +205,9 @@ public function render(OutputFormat $outputFormat): string
202205
{
203206
$locale = \localeconv();
204207
$decimalPoint = \preg_quote($locale['decimal_point'], '/');
205-
$size = \preg_match('/[\\d\\.]+e[+-]?\\d+/i', (string) $this->size)
206-
? \preg_replace("/$decimalPoint?0+$/", '', \sprintf('%f', $this->size)) : (string) $this->size;
208+
$size = preg_match('/[\\d\\.]+e[+-]?\\d+/i', (string) $this->size) === 1
209+
? preg_replace("/$decimalPoint?0+$/", '', \sprintf('%f', $this->size)) : (string) $this->size;
207210

208-
return \preg_replace(["/$decimalPoint/", '/^(-?)0\\./'], ['.', '$1.'], $size) . ($this->unit ?? '');
211+
return preg_replace(["/$decimalPoint/", '/^(-?)0\\./'], ['.', '$1.'], $size) . ($this->unit ?? '');
209212
}
210213
}

0 commit comments

Comments
 (0)