Skip to content
This repository

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

Merged
merged 1 commit into from over 1 year ago

2 participants

Luca Simone Charles Oliver Nutter
Luca Simone
lukefx commented May 24, 2012

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 October 26, 2012
Charles Oliver Nutter headius closed this October 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 24, 2012
Luca Simone JRUBY-2724: I've added some tests and I tried to fix unc pathing 8cc8248
This page is out of date. Refresh to see the latest.
14  src/org/jruby/RubyFile.java
@@ -613,6 +613,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
613 613
         } else {
614 614
             //TODO deal with UNC names
615 615
             int index = name.lastIndexOf('/');
  616
+
616 617
             if (index == -1) {
617 618
                 if (startsWithDriveLetterOnWindows) {
618 619
                     return context.getRuntime().newString(jfilename.substring(0, 2) + ".");
@@ -628,9 +629,20 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
628 629
                 index++;
629 630
             }
630 631
 
  632
+            if (jfilename.startsWith("\\\\")) {
  633
+                index = jfilename.length();
  634
+                String[] splitted = jfilename.split(Pattern.quote("\\"));
  635
+                int last = splitted.length-1;
  636
+                if (splitted[last].contains(".")) {
  637
+                    index = jfilename.lastIndexOf("\\");
  638
+                }
  639
+                
  640
+            }
  641
+            
631 642
             result = jfilename.substring(0, index);
  643
+            
632 644
         }
633  
-
  645
+        
634 646
         char endChar;
635 647
         // trim trailing slashes
636 648
         while (result.length() > minPathLength) {
9  test/test_file.rb
@@ -108,6 +108,15 @@ def test_windows_dirname
108 108
       assert_equal "C:/temp", File.dirname("C:/temp/foobar.txt")
109 109
     end
110 110
 
  111
+	def test_windows_network_path
  112
+	
  113
+		assert_equal("\\\\network\\share", File.dirname("\\\\network\\share\\file.bat"))
  114
+		assert_equal("\\\\network\\share", File.dirname("\\\\network\\share"))
  115
+		assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$\\boot.bat"))
  116
+		assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$"))
  117
+	
  118
+	end
  119
+
111 120
     def test_expand_path_windows
112 121
       assert_equal("C:/", File.expand_path("C:/"))
113 122
       assert_equal("C:/dir", File.expand_path("C:/dir"))
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.