Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File name convention, reserved file names incomplete? #199

Open
madig opened this issue Jan 17, 2022 · 8 comments
Open

File name convention, reserved file names incomplete? #199

madig opened this issue Jan 17, 2022 · 8 comments
Labels
approved Approved specification change. ufo3 UFO 3 issues.

Comments

@madig
Copy link
Contributor

madig commented Jan 17, 2022

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
Copy link
Contributor Author

madig commented Jan 17, 2022

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
Copy link
Contributor Author

madig commented Jan 17, 2022

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
Copy link
Contributor Author

madig commented Jan 17, 2022

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:

  • Maximum file name length as before, 255.
  • Illegal characters to be replaced by an underscore: [':', '?', '"', '(', ')', '[', ']', '*', '/', '\\', '+', '<', '>', '|'] (Not sure why "()" are disallowed by the spec?)
  • Reserved (full!) file names to be prefixed by an underscore: ["con", "prn", "aux", "nul", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9"] (Note that this means "com1.txt" and "com1" but not "hello.com1.txt" and "hello.com1")
  • Trailing periods and spaces of the full name are replaced by underscores.
  • Uniqueness as before.

How'd that sound?

@benkiel
Copy link
Contributor

benkiel commented Jan 20, 2022

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
Copy link
Contributor

benkiel commented Jan 21, 2022

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

@benkiel benkiel added approved Approved specification change. ufo3 UFO 3 issues. labels Jan 21, 2022
@madig
Copy link
Contributor Author

madig commented Jan 21, 2022

I started something at fonttools/fonttools#2506 -- if that's ok to merge, I can expand the spec.

@benkiel
Copy link
Contributor

benkiel commented Jan 21, 2022

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

@madig
Copy link
Contributor Author

madig commented Jan 24, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved specification change. ufo3 UFO 3 issues.
Projects
None yet
Development

No branches or pull requests

2 participants