Skip to content

Commit

Permalink
JRUBY-6135: CASEFOLD systems magically screw up globs with . or .. in…
Browse files Browse the repository at this point in the history
… them
  • Loading branch information
enebo committed Oct 12, 2011
1 parent 771d625 commit 62d305f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/org/jruby/util/Dir.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,16 @@ public DirGlobber(ByteList link, JarEntry jarEntry) {
}
}

private static boolean isSpecialFile(String name) {
int length = name.length();

if (length < 1 || length > 3 || name.charAt(0) != '.') return false;
if (length == 1) return true;
char c = name.charAt(1);
if (length == 2 && (c == '.' || c == '/')) return true;
return c == '.' && name.charAt(2) == '/';
}

private static int addToResultIfExists(String cwd, byte[] bytes, int begin, int end, int flags, GlobFunc func, GlobArgs arg) {
String fileName = newStringFromUTF8(bytes, begin, end - begin);
JavaSecuredFile file = cwd != null ? new JavaSecuredFile(cwd, fileName) :
Expand All @@ -576,7 +586,7 @@ private static int addToResultIfExists(String cwd, byte[] bytes, int begin, int

// On case-insenstive file systems any case string will 'exists',
// but what does it display as if you ls/dir it?
if ((flags & FNM_CASEFOLD) != 0) {
if ((flags & FNM_CASEFOLD) != 0 && !isSpecialFile(fileName)) {
try {
String realName = file.getCanonicalFile().getName();

Expand Down

0 comments on commit 62d305f

Please sign in to comment.