@@ -68,14 +68,14 @@ public function __construct($text, Settings $parserSettings, $lineNumber = 1)
6868
6969 /**
7070 * 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
7173 */
7274 public function setCharset (string $ charset ): void
7375 {
7476 $ this ->charset = $ charset ;
7577 $ 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 );
7979 }
8080
8181 /**
@@ -466,12 +466,18 @@ private function strtolower($sString): string
466466 * @param string $sString
467467 *
468468 * @return array<int, string>
469+ *
470+ * @throws SourceException if the charset is UTF-8 and the string contains invalid byte sequences
469471 */
470472 private function strsplit ($ sString )
471473 {
472474 if ($ this ->parserSettings ->bMultibyteSupport ) {
473475 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 ;
475481 } else {
476482 $ length = \mb_strlen ($ sString , $ this ->charset );
477483 $ result = [];
0 commit comments