Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Please also have a look at our

### Fixed

- Use typesafe versions of PHP functions (#1368)
- Use typesafe versions of PHP functions (#1368, #1370)

### Documentation

Expand Down
25 changes: 11 additions & 14 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Settings;

use function Safe\iconv;
use function Safe\preg_match;
use function Safe\preg_split;

/**
* @internal since 8.7.0
*/
Expand Down Expand Up @@ -63,8 +67,6 @@ public function __construct(string $text, Settings $parserSettings, int $lineNum

/**
* Sets the charset to be used if the CSS does not contain an `@charset` declaration.
*
* @throws SourceException if the charset is UTF-8 and the content has invalid byte sequences
*/
public function setCharset(string $charset): void
{
Expand Down Expand Up @@ -122,7 +124,7 @@ public function parseIdentifier(bool $ignoreCase = true): string
}
$character = null;
while (!$this->isEnd() && ($character = $this->parseCharacter(true)) !== null) {
if (\preg_match('/[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_-]/Sux', $character)) {
if (preg_match('/[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_-]/Sux', $character) !== 0) {
$result .= $character;
} else {
$result .= '\\' . $character;
Expand All @@ -146,13 +148,13 @@ public function parseCharacter(bool $isForIdentifier): ?string
if ($this->comes('\\n') || $this->comes('\\r')) {
return '';
}
if (\preg_match('/[0-9a-fA-F]/Su', $this->peek()) === 0) {
if (preg_match('/[0-9a-fA-F]/Su', $this->peek()) === 0) {
return $this->consume(1);
}
$hexCodePoint = $this->consumeExpression('/^[0-9a-fA-F]{1,6}/u', 6);
if ($this->strlen($hexCodePoint) < 6) {
// Consume whitespace after incomplete unicode escape
if (\preg_match('/\\s/isSu', $this->peek())) {
if (preg_match('/\\s/isSu', $this->peek()) !== 0) {
if ($this->comes('\\r\\n')) {
$this->consume(2);
} else {
Expand All @@ -166,7 +168,7 @@ public function parseCharacter(bool $isForIdentifier): ?string
$utf32EncodedCharacter .= \chr($codePoint & 0xff);
$codePoint = $codePoint >> 8;
}
return \iconv('utf-32le', $this->charset, $utf32EncodedCharacter);
return iconv('utf-32le', $this->charset, $utf32EncodedCharacter);
}
if ($isForIdentifier) {
$peek = \ord($this->peek());
Expand Down Expand Up @@ -198,7 +200,7 @@ public function consumeWhiteSpace(): array
{
$comments = [];
do {
while (\preg_match('/\\s/isSu', $this->peek()) === 1) {
while (preg_match('/\\s/isSu', $this->peek()) === 1) {
$this->consume(1);
}
if ($this->parserSettings->usesLenientParsing()) {
Expand Down Expand Up @@ -291,7 +293,7 @@ public function consumeExpression(string $expression, ?int $maximumLength = null
{
$matches = null;
$input = ($maximumLength !== null) ? $this->peek($maximumLength) : $this->inputLeft();
if (\preg_match($expression, $input, $matches, PREG_OFFSET_CAPTURE) !== 1) {
if (preg_match($expression, $input, $matches, PREG_OFFSET_CAPTURE) !== 1) {
throw new UnexpectedTokenException($expression, $this->peek(5), 'expression', $this->lineNumber);
}

Expand Down Expand Up @@ -437,17 +439,12 @@ private function strtolower(string $string): string

/**
* @return list<string>
*
* @throws SourceException if the charset is UTF-8 and the string contains invalid byte sequences
*/
private function strsplit(string $string): array
{
if ($this->parserSettings->hasMultibyteSupport()) {
if ($this->streql($this->charset, 'utf-8')) {
$result = \preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
if (!\is_array($result)) {
throw new SourceException('`preg_split` failed with error ' . \preg_last_error());
}
$result = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
} else {
$length = \mb_strlen($string, $this->charset);
$result = [];
Expand Down