Phango

Janice Caron caron800 at googlemail.com
Fri Nov 16 06:58:58 PST 2007


I dunno if you'd consider this a bug in tango.io.filepath.parse(), but
the example program filepathname.d looks like this:

    void main(){
        Cout ((new FilePath(r"d:\path\foo.bat")).name).newline;
        Cout ((new FilePath(r"d:\path.two\bar")).name).newline;
        Cout ((new FilePath("/home/user.name/bar.")).name).newline;
        Cout ((new FilePath(r"d:\path.two\bar")).name).newline;
        Cout ((new FilePath("/home/user/.resource")).name).newline;
    }

And (on Windows) emits the following output - at least, on my ported version:

    foo
    bar
    /home/user.name/bar
    bar
    /home/user/

I think I understand what's going on here. The slash in the third and
fifth examples is being (incorrectly) regarded as a component
character, instead of a path separator, so it thinks "/home/user/" is
the file part and "resource" the extension.

Yes, I know there's a flag in the constructor which converts "\" to
"/", and that that flag wasn't set in this example, BUT...

In Windows, "\" and "/" are BOTH acceptable as file separators. As far
as fopen() is concerned, they are interchangable. If you open
"/home/user/.resource" you'll get exactly the same file as had you
opened "\home\user\.resource".

This isn't true in a Windows (Command Prompt) shell, however, even
there, "/" is not a valid character for use in filenames. In fact, all
of the characters \ / : * ? " < > and | are prohibited from being used
in filenames.

I feel that the filepath.parse routine really should understand how
pathnames actually work on Windows. Sure, if the native flag is set,
then convert / to \. But even if that doesn't happen, parse() should
recognise both \ and / as pathname separators, and should throw an
exception if an illegal character is used in a pathname.

If there are no objections, I plan to "fix" this in my local copy, and
I can certainly post the fix for you, in case you should want to
incorporate it into the real Tango.



More information about the Digitalmars-d mailing list