fix: strip whitespace from filename in two-arg open - #429
Draft
toddr-bot wants to merge 1 commit into
Draft
Conversation
Real Perl strips leading and trailing whitespace from the filename
portion of two-arg open() after extracting the mode prefix. MockFile
captured the whitespace literally, causing open("< /path") and
open(" /path ") to fail matching the mocked file at /path.
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
Two-arg
open()now strips leading/trailing whitespace from the filename, matching real Perl behavior.Why
open(my $fh, "< /path/to/file")is a common Perl idiom. The space after<is stripped by real Perl but was captured literally by MockFile's mode-parsing regex, causing the path to not match any mock. Fixes #428.How
Added whitespace stripping (
s/^\s+//; s/\s+$//) to the two-arg normalization in__open— both the mode-prefix branch and the bare-filename branch. Three-arg open is unaffected (no mode parsing involved).Testing
New
t/open_two_arg_whitespace.twith 11 subtests covering all six mode prefixes, multiple spaces, tabs, bare filenames, and a regression check that three-arg open preserves spaces in filenames.Full suite: 1594/1597 pass (3 failures in
fh-ref-leak.tare pre-existing).Quality Report
Changes: 2 files changed, 110 insertions(+)
Code scan: clean
Tests: failed (4 Failed, 95 test)
Branch hygiene: clean
Generated by Kōan