Permalink
Browse files

JRUBY-2724: I've added some tests and I tried to fix unc pathing

  • Loading branch information...
1 parent d745248 commit 8cc824827e62c4334034075ee87f364ab230e283 @lukefx committed May 24, 2012
Showing with 22 additions and 1 deletion.
  1. +13 −1 src/org/jruby/RubyFile.java
  2. +9 −0 test/test_file.rb
@@ -613,6 +613,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
} else {
//TODO deal with UNC names
int index = name.lastIndexOf('/');
+
if (index == -1) {
if (startsWithDriveLetterOnWindows) {
return context.getRuntime().newString(jfilename.substring(0, 2) + ".");
@@ -628,9 +629,20 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
index++;
}
+ if (jfilename.startsWith("\\\\")) {
+ index = jfilename.length();
+ String[] splitted = jfilename.split(Pattern.quote("\\"));
+ int last = splitted.length-1;
+ if (splitted[last].contains(".")) {
+ index = jfilename.lastIndexOf("\\");
+ }
+
+ }
+
result = jfilename.substring(0, index);
+
}
-
+
char endChar;
// trim trailing slashes
while (result.length() > minPathLength) {
View
@@ -108,6 +108,15 @@ def test_windows_dirname
assert_equal "C:/temp", File.dirname("C:/temp/foobar.txt")
end
+ def test_windows_network_path
+
+ assert_equal("\\\\network\\share", File.dirname("\\\\network\\share\\file.bat"))
+ assert_equal("\\\\network\\share", File.dirname("\\\\network\\share"))
+ assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$\\boot.bat"))
+ assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$"))
+
+ end
+
def test_expand_path_windows
assert_equal("C:/", File.expand_path("C:/"))
assert_equal("C:/dir", File.expand_path("C:/dir"))

0 comments on commit 8cc8248

Please sign in to comment.