Skip to content

File.fnmatch with File::FNM_PATHNAME doesn't treat [/a] or [a/] like [a] as MRI does #6193

@robotdana

Description

@robotdana

File.fnmatch with File::FNM_PATHNAME doesn't treat [/a] like [a] as MRI does, it seems like it treats it like [] instead:

Here's a travis build and sample project:

https://travis-ci.org/github/robotdana/jruby-fnmatch/jobs/679588429

https://github.com/robotdana/jruby-fnmatch

The failing examples (that pass on at least mri 2.4-2.7) are:
expect(::File.fnmatch?('a[a/]a', 'aaa', ::File::FNM_PATHNAME)).to be true
expect(::File.fnmatch?('a[/a]a', 'aaa', ::File::FNM_PATHNAME)).to be true

MRI seems to be interpreting the pattern as a[a]a, while jruby seems to be interpreting it as a[]a that is, a pattern that will match nothing.

The behaviour here is not documented either way https://ruby-doc.org/core-2.5.0/File.html#method-c-fnmatch so i'm not sure if it counts it as a bug, but it seems to have consistently worked that way in MRI. (also in git which like mri also uses c fnmatch internally, and is how i stumbled across this inconsistency when adding jruby to the test matrix for https://github.com/robotdana/fast_ignore)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions