@@ -68,14 +68,14 @@ public function __construct($text, Settings $parserSettings, $lineNumber = 1)
68
68
69
69
/**
70
70
* Sets the charset to be used if the CSS does not contain an `@charset` declaration.
71
+ *
72
+ * @throws SourceException if the charset is UTF-8 and the content has invalid byte sequences
71
73
*/
72
74
public function setCharset (string $ charset ): void
73
75
{
74
76
$ this ->charset = $ charset ;
75
77
$ this ->characters = $ this ->strsplit ($ this ->text );
76
- if (\is_array ($ this ->characters )) {
77
- $ this ->length = \count ($ this ->characters );
78
- }
78
+ $ this ->length = \count ($ this ->characters );
79
79
}
80
80
81
81
/**
@@ -466,12 +466,18 @@ private function strtolower($sString): string
466
466
* @param string $sString
467
467
*
468
468
* @return array<int, string>
469
+ *
470
+ * @throws SourceException if the charset is UTF-8 and the string contains invalid byte sequences
469
471
*/
470
472
private function strsplit ($ sString )
471
473
{
472
474
if ($ this ->parserSettings ->bMultibyteSupport ) {
473
475
if ($ this ->streql ($ this ->charset , 'utf-8 ' )) {
474
- return \preg_split ('//u ' , $ sString , -1 , PREG_SPLIT_NO_EMPTY );
476
+ $ result = \preg_split ('//u ' , $ sString , -1 , PREG_SPLIT_NO_EMPTY );
477
+ if (!\is_array ($ result )) {
478
+ throw new SourceException ('`preg_split` failed with error ' . \preg_last_error ());
479
+ }
480
+ return $ result ;
475
481
} else {
476
482
$ length = \mb_strlen ($ sString , $ this ->charset );
477
483
$ result = [];
0 commit comments