Skip to content

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

Description

@toddr-bot

Bug

Two-arg open() with whitespace between the mode prefix and filename fails to match mocked files.

my $mock = Test::MockFile->file('/tmp/file', 'hello');

# Works:
open(my $fh1, '</tmp/file');

# Fails with ENOENT — Perl strips the space, MockFile doesn't:
open(my $fh2, '< /tmp/file');

Real Perl strips leading and trailing whitespace from the filename portion after extracting the mode prefix (<, >, >>, +<, +>, +>>). This is a common Perl idiom (open(my $fh, "> $path") with a space for readability).

MockFile's regex captures the whitespace literally, producing a path like /tmp/file that doesn't match the mock registered at /tmp/file.

Affected modes

All two-arg modes: <, >, >>, +<, +>, +>>, and bare filenames (no mode prefix).

Not affected

  • Three-arg open(FH, '<', $path) — filename comes from a separate argument, no mode parsing
  • Pipe modes (|-, -|) — fall through to CORE::open

🤖 Created by Kōan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions