fix: prevent infinite loop in Datafile plugin on empty files#390
Draft
toddr-bot wants to merge 1 commit intoabw:masterfrom
Draft
fix: prevent infinite loop in Datafile plugin on empty files#390toddr-bot wants to merge 1 commit intoabw:masterfrom
toddr-bot wants to merge 1 commit intoabw:masterfrom
Conversation
…iles The header-reading loop in Datafile.pm's constructor would spin forever when the file was empty or contained only comment lines. The <FD> read returns undef at EOF, but the loop condition `! $line` treats undef as falsy, so it re-enters the loop and reads undef again indefinitely. Add an early exit when the filehandle returns undef. The existing error check on line 53 then correctly reports "first line of file must contain field names." Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an EOF check to the header-reading loop in
Template::Plugin::Datafileto prevent infinite loops.Why
When a datafile is empty or contains only comment lines, the constructor's header-reading
whileloop spins forever:<FD>returnsundefat EOF,! $lineevaluates as true (undef is falsy), and the loop re-enters indefinitely. This hangs any template that tries to load such a file.How
One-line fix:
last unless defined $line;after the filehandle read. When EOF is reached, the loop exits and the existing error check on line 53 correctly returns "first line of file must contain field names."Testing
t/datafile_edge.twith Test::More covering:t/datafile.tpasses unchanged🤖 Generated with Claude Code