Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dce18444ee79
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5162ea5580a5
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 18, 2015

  1. Copy the full SHA
    bd26e8d View commit details
  2. Copy the full SHA
    5162ea5 View commit details
Showing with 14 additions and 6 deletions.
  1. +10 −6 core/src/main/java/org/jruby/util/Dir.java
  2. +4 −0 spec/ruby/core/file/shared/fnmatch.rb
16 changes: 10 additions & 6 deletions core/src/main/java/org/jruby/util/Dir.java
Original file line number Diff line number Diff line change
@@ -64,10 +64,14 @@ public class Dir {
public final static byte[] STAR = new byte[]{'*'};
public final static byte[] DOUBLE_STAR = new byte[]{'*','*'};

private static boolean isdirsep(byte c) {
private static boolean isdirsep(char c) {
return c == '/' || DOSISH && c == '\\';
}

private static boolean isdirsep(byte c) {
return isdirsep((char)(c & 0xFF));
}

private static int rb_path_next(byte[] _s, int s, int send) {
while(s < send && !isdirsep(_s[s])) {
s++;
@@ -85,7 +89,7 @@ private static int fnmatch_helper(byte[] bytes, int pstart, int pend, byte[] str
boolean nocase = (flags & FNM_CASEFOLD) != 0;

while(pat<pend) {
byte c = bytes[pat++];
char c = (char)(bytes[pat++] & 0xFF);
switch(c) {
case '?':
if(s >= send || (pathname && isdirsep(string[s])) ||
@@ -95,7 +99,7 @@ private static int fnmatch_helper(byte[] bytes, int pstart, int pend, byte[] str
s++;
break;
case '*':
while(pat < pend && (c = bytes[pat++]) == '*') {}
while(pat < pend && (c = (char)(bytes[pat++] & 0xFF)) == '*') {}
if(s < send && (period && string[s] == '.' && (s == 0 || (pathname && isdirsep(string[s-1]))))) {
return FNM_NOMATCH;
}
@@ -113,7 +117,7 @@ private static int fnmatch_helper(byte[] bytes, int pstart, int pend, byte[] str
}
return FNM_NOMATCH;
}
test = (char)((escape && c == '\\' && pat < pend ? bytes[pat] : c)&0xFF);
test = (char)(escape && c == '\\' && pat < pend ? (bytes[pat] & 0xFF) : c);
test = Character.toLowerCase(test);
pat--;
while(s < send) {
@@ -142,7 +146,7 @@ private static int fnmatch_helper(byte[] bytes, int pstart, int pend, byte[] str
if (pat >= pend) {
c = '\\';
} else {
c = bytes[pat++];
c = (char)(bytes[pat++] & 0xFF);
}
}
default:
@@ -157,7 +161,7 @@ private static int fnmatch_helper(byte[] bytes, int pstart, int pend, byte[] str
}

} else {
if(c != (char)string[s]) {
if(c != (char)(string[s] & 0xFF)) {
return FNM_NOMATCH;
}
}
4 changes: 4 additions & 0 deletions spec/ruby/core/file/shared/fnmatch.rb
Original file line number Diff line number Diff line change
@@ -234,4 +234,8 @@
flags.should_receive(:to_int).and_return(10)
lambda { File.send(@method, "*/place", "path/to/file", flags) }.should_not raise_error
end

it "matches multibyte characters" do
File.fnmatch("*/ä/ø/ñ", "a/ä/ø/ñ").should == true
end
end