Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

Luca Simone Charles Oliver Nutter
Luca Simone

It's not great, but passes some UNC cases.
Maybe the entire function should be rewritten with some regex that treats the various edge cases.

Charles Oliver Nutter
Owner

I'm game to get this into 1.7.1. How do we feel about this?

Luca Simone

Let me know if needs more test or whatever...

Charles Oliver Nutter headius merged commit ad60957 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 1 deletion.
  1. +13 −1 src/org/jruby/RubyFile.java
  2. +9 −0 test/test_file.rb
14 src/org/jruby/RubyFile.java
View
@@ -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) {
9 test/test_file.rb
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"))
Something went wrong with that request. Please try again.