Skip to content

fix: strip whitespace from filename in two-arg open - #429

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-two-arg-open-whitespace
Draft

fix: strip whitespace from filename in two-arg open#429
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-two-arg-open-whitespace

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

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.t with 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.t are 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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: two-arg open() doesn't strip whitespace from filename like real Perl

1 participant