[Win32utils-devel] [ win32utils-Bugs-28499 ] File.dirname should not consider trailing slashes

noreply at rubyforge.org noreply at rubyforge.org
Sun Aug 29 11:46:17 EDT 2010


Bugs item #28499, was opened at 2010-08-24 21:47
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=411&aid=28499&group_id=85

Category: win32-file
Group: Code
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Daniel Berger (djberg96)
>Assigned to: Daniel Berger (djberg96)
Summary: File.dirname should not consider trailing slashes

Initial Comment:
The PathRemoveFileSpec function says it removes the trailing file name and backslash from a path if present. However, this doesn't seem to be the case with the wide character functions:

require 'win32/file'

irb(main):005:0> File.dirname("//foo/bar/baz")
=> "\\foo\bar"
irb(main):006:0> File.dirname("//foo/bar/baz/")
=> "\\foo\bar\baz"

That is not correct.

Regards

Dan (me)

----------------------------------------------------------------------

>Comment By: Daniel Berger (djberg96)
Date: 2010-08-29 08:46

Message:
Unfortunately that patch caused some other test failures. I ended up using PathRemoveBackslash, combined with a short circuit for empty paths, to solve it. I also added some more tests.

Fixed in git, I'll push out a release tonight.

Regards,

Dan

----------------------------------------------------------------------

Comment By: Park Heesob  (phasis68)
Date: 2010-08-24 22:52

Message:
Although I understand the behaviour, that is not correct in view of RubyDoc.

Here is a simple patch.

--- file.rb.org 2010-08-25 14:40:52.846324163 +0900
+++ file.rb     2010-08-25 14:40:52.734575269 +0900
@@ -514,7 +514,7 @@
     #
     def dirname(file)
       raise TypeError unless file.is_a?(String)
-      file = multi_to_wide(file)
+      file = multi_to_wide(file.gsub(/[\/\]+$/,''))

       # Convert slashes to backslashes for the Windows API functions
       file.tr!(File::SEPARATOR, File::ALT_SEPARATOR)


Regards,
Park Heesob

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=411&aid=28499&group_id=85


More information about the win32utils-devel mailing list