From: Austin Ziegler Date: 2005-09-14T03:56:16+09:00 Subject: Re: File.split edge cases On 9/13/05, Daniel Berger wrote: > Austin Ziegler wrote: >> Assuming that File.split should be implemented as [ File.dirname, >> File.basename ]: >> >> % dirname /foo/bar/ >> /foo >> % basename /foo/bar/ >> bar >> % dirname / >> / >> % basename / >> / [...] > Yeah, the closer I look at posixpath, the more I realize it's.... > wrong. Well, damn, with a name like "posixpath" you would *think* it > would be correct, eh? One might. ;) >> Ruby has it right in both cases. On Windows, File.split() should be a >> bit smarter: >> >> File.split("C:\\") # => [ "C:", "\\" ] >> File.split("\\\\server\\path\\") # => [ "\\\\server\\path", "\\" ] > Yes, I think really all that's needed are explicit checks for empty > and root paths: > # pseudo-code > if path.root? or path.empty? > return path, "" > else > return File.dirname(path), File.basename(path) > end Hmmm. I don't think that's right, still. "ls //" is valid on Unix, so the existing behaviour is *correct*, if mildly unnerving. However, on Windows, "dir \\" is not correct just as "dir C:\\" will not be correct. Better to specifically check for the UNC-path and drive-path cases. Ruby should also be smart enough to handle the \\.\ and \\?\ special prefixes. I can write up a summary of what these are for and how they should be handled, if that would help. I believe that if this is fixed, it should go into 1.8.3 as well as 1.9. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca