Project

General

Profile

Actions

Feature #14570

open

Make File.expand_path/real_path casing consistent on Windows

Added by larskanis (Lars Kanis) over 6 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:85900]
Tags:

Description

File.realpath returns the path with the same upper/lower case characters as the input parameter. But File.expand_path is different. It adjusts the last part of the path (and only this) to the upper/lower case characters given from the file system.

require "fileutils"
FileUtils.mkdir_p("TestDir/abC/Xyz")

File.expand_path("testdir") # => "C:/Users/lars/TestDir"
File.expand_path("testdir/abc") # => "C:/Users/lars/testdir/abC"
File.expand_path("testdir/abc/XYZ") # => "C:/Users/lars/testdir/abc/Xyz"

File.realpath("testdir") # => "C:/Users/lars/testdir"
File.realpath("testdir/abc") # => "C:/Users/lars/testdir/abc"
File.realpath("testdir/abc/XYZ") # => "C:/Users/lars/testdir/abc/XYZ"

The file system on Windows is case insensitive. So this is not really a bug, but it's inconsistent and unexpected. I would expect that File.expand_path returns a path with upper/lowercase either entirely retrieved from the input parameter or from the file system, but not a mixture of both. I would also expect that File.realpath and File.expand_path have the same semantics in this regard.

Same behavior on ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32]

Updated by graywolf (Gray Wolf) over 6 years ago

If the behaviour is adjusted to reflect the filesystem, it would be nice to do the same for __FILE__ (and I assume also __dir__). At the moment __FILE__ doesn't necessarily match file system casing. Again, same as in the post above, since windows are case insensitive it's not technically a bug, but if File.realpath (expand_path) are changed to reflect real casing, __FILE__ should probably also be changed.

Actions #2

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

  • Tracker changed from Bug to Feature
  • Subject changed from Wired behavior of File.expand_path() on Windows to Make File.expand_path/real_path casing consistent on Windows
  • ruby -v deleted (ruby 2.6.0dev (2018-02-22 trunk 62518) [x64-mingw32])
  • Backport deleted (2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0