Skip to content

Commit

Permalink
fnmatch not matching glob syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ahorek committed Oct 5, 2023
1 parent 315c073 commit c00a06e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/org/jruby/util/Dir.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ int helper(byte[] pbytes, int pend, byte[] sbytes, int send, Encoding enc) {
while (true) {
// in place of expected C null char check that falls into default in switch below
if (p >= pend) {
return isEnd(sbytes, s, send) ? 0 : FNM_NOMATCH;
if (isEnd(sbytes, s, send)) {
return 0;
}
// failed
if (ptmp != -1 && stmp != -1) {
p = ptmp;
stmp++; /* !ISEND(*stmp) */
s = stmp;
continue;
}
return FNM_NOMATCH;
}

switch (pbytes[p]) {
Expand Down
7 changes: 7 additions & 0 deletions spec/ruby/core/file/shared/fnmatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@
end
end

it "matches wildcard with characters when flags includes FNM_PATHNAME" do
File.send(@method, '*a', 'aa', File::FNM_PATHNAME).should == true
File.send(@method, 'a*', 'aa', File::FNM_PATHNAME).should == true
File.send(@method, 'a*', 'aaa', File::FNM_PATHNAME).should == true
File.send(@method, '*a', 'aaa', File::FNM_PATHNAME).should == true
end

it "does not match '/' characters with ? or * when flags includes FNM_PATHNAME" do
File.send(@method, '?', '/', File::FNM_PATHNAME).should == false
File.send(@method, '*', '/', File::FNM_PATHNAME).should == false
Expand Down

0 comments on commit c00a06e

Please sign in to comment.