Skip to content

Commit 3a8a43b

Browse files
aymanrbclaude
andcommitted
Guard against empty or whitespace-only input in parseText()
When parseText() is called with an empty or whitespace-only string, similarity matching against templates via similar_text() produces undefined/meaningless scores and brute-force matching wastes cycles. Return early with an empty ParseResult and log a warning instead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 94da5b6 commit 3a8a43b

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/TextParser.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public function parseText(string $text, bool $findMatchingTemplate = false): Par
4444
{
4545
$this->resetParseResults();
4646

47+
if (trim($text) === '') {
48+
$this->logger->warning('parseText called with empty or whitespace-only text, skipping parsing');
49+
50+
return $this->parseResults;
51+
}
52+
4753
$parsableTemplates = $this->templatesHelper->getTemplates($text, $findMatchingTemplate);
4854

4955
foreach ($parsableTemplates as $templatePath => $templatePattern) {

0 commit comments

Comments
 (0)