Skip to content

Commit ea1de49

Browse files
deemonicclaude
andcommitted
fix: guard against preg_replace returning null on malformed UTF-8
preg_replace with /u flag returns null on invalid UTF-8 input. Fall back to the original text to avoid silently losing input. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bcc0d89 commit ea1de49

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/Core/Analyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function analyze(
1919

2020
// Strip invisible Unicode format characters (zero-width spaces, invisible separators, etc.)
2121
// before any driver sees the text, ensuring consistent positions across pipeline drivers
22-
$text = preg_replace('/\p{Cf}/u', '', $text);
22+
$text = preg_replace('/\p{Cf}/u', '', $text) ?? $text;
2323

2424
return $driver->detect($text, $dictionary, $mask, $options);
2525
}

0 commit comments

Comments
 (0)