Skip to content

Commit bcdf196

Browse files
authored
Merge pull request #7947 from ahorek/fnmatch
fnmatch not matching glob syntax
2 parents f9abf45 + a39cd49 commit bcdf196

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

core/src/main/java/org/jruby/util/Dir.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ int helper(byte[] pbytes, int pend, byte[] sbytes, int send, Encoding enc) {
124124
while (true) {
125125
// in place of expected C null char check that falls into default in switch below
126126
if (p >= pend) {
127-
return isEnd(sbytes, s, send) ? 0 : FNM_NOMATCH;
127+
if (isEnd(sbytes, s, send)) {
128+
return 0;
129+
}
130+
// failed
131+
if (ptmp != -1 && stmp != -1) {
132+
p = ptmp;
133+
stmp++; /* !ISEND(*stmp) */
134+
s = stmp;
135+
continue;
136+
}
137+
return FNM_NOMATCH;
128138
}
129139

130140
switch (pbytes[p]) {

spec/ruby/core/file/shared/fnmatch.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@
125125
end
126126
end
127127

128+
it "matches wildcard with characters when flags includes FNM_PATHNAME" do
129+
File.send(@method, '*a', 'aa', File::FNM_PATHNAME).should == true
130+
File.send(@method, 'a*', 'aa', File::FNM_PATHNAME).should == true
131+
File.send(@method, 'a*', 'aaa', File::FNM_PATHNAME).should == true
132+
File.send(@method, '*a', 'aaa', File::FNM_PATHNAME).should == true
133+
end
134+
128135
it "does not match '/' characters with ? or * when flags includes FNM_PATHNAME" do
129136
File.send(@method, '?', '/', File::FNM_PATHNAME).should == false
130137
File.send(@method, '*', '/', File::FNM_PATHNAME).should == false

0 commit comments

Comments
 (0)