unified-font-object / ufo-spec

The official Unified Font Object specification source files.
http://unifiedfontobject.org
175 stars 30 forks source link

File name convention, reserved file names incomplete? #199

Open madig opened 2 years ago

madig commented 2 years ago

According to https://docs.microsoft.com/en-gb/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#naming-conventions, the reserved file names are:

Do not use the following reserved names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended. For more information, see Namespaces.

Should the spec be upated to contain only those? Note how "CLOCK$" and drive letters aren't mentioned (colons are replaced already anyway).

There's also https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/b04c3bd0-79dc-4e58-b8ed-74f19fc2ea0a. Not sure they should be reserved names as well?

madig commented 2 years ago

Also, I can create a file named "hello.com1.txt" on my Windows 10 21H2 (and some Windows XP) PC. Where does the

Use period as a delimiter to split name into parts.

part in the spec come from? Is it maybe enough to just look at the string as a whole?

Edit: I can't create a file named "com1 " (note the space) but "com1 .txt" is fine. userNameToFileName won't prevent the former.

madig commented 2 years ago

Also, the spec says that e.g. "C:" is a reserved file name, but I don't think this needs to be checked, because the colon is already unconditionally replaced in the first step.

madig commented 2 years ago

The following links say somewhat inconsistent things about what is illegal and reserved:

I also found that I can't name things e.g. "com0.txt" on my Windows machine in Explorer, but can in PowerShell. Hm.

So, maybe the algorithm needs to be changed a bit. If we say we support (V|ex)FAT, NTFS, HFS(+) and any POSIXy filesystem, as the 255 character limit suggests, and none of the old DOS crap, it could instead ensure:

How'd that sound?

benkiel commented 2 years ago

That sounds/seems fine. I would venture to guess that the last item (Trailing periods and spaces) may be a breaking change. For the ( & ) rule; I'm not sure why they aren't allowed, but I would not remove them from that list; not allowing them hasn't been an issue so far, no need to touch want isn't broken.

benkiel commented 2 years ago

(@madig I'm assuming you may PR this change?)

madig commented 2 years ago

I started something at https://github.com/fonttools/fonttools/pull/2506 -- if that's ok to merge, I can expand the spec.

benkiel commented 2 years ago

That PR looks good to merge, but I'll let others chime in there. Thank you for doing the spec update!

madig commented 2 years ago

Leftover todo after merged #204:

  1. Reserved filename escaping can be less aggressive that it is currently because only the part before the first period is relevant (i.e. "con" and "con.txt" but not "hello.con" and "hello.con.txt")
  2. Trailing periods and spaces of the full name must be escaped for Windows filesystems.