Godot: `is_valid_filename()` returns `true` for Windows-reserved filenames like NUL and CON

Created on 25 Apr 2020  路  9Comments  路  Source: godotengine/godot

Godot version:
3.2.1.stable

OS/device including version:
Windows

Issue description:
is_valid_filename() returns true for Windows reserved filenames

Steps to reproduce:
print("Con".is_valid_filename())

Minimal reproduction project:
Thank you so much :)

bug windows core

Most helpful comment

Related to #20110.

As much as it sucks that Windows has such outdated filename restrictions, I guess we should extend them to all platforms to ensure cross-platform compatibility.

All 9 comments

The question is, should we make it return false on other platforms where Con or NUL are valid filenames? Or should we err on the side of caution and return false on all platforms?

Maybe a parameter inside the is_valid_filename(IsValid for all platforms) ?
I'm not sure either

@LoneDespair I don't know, there needs to be a valid usecase to support both kinds of checks.

Related to #20110.

As much as it sucks that Windows has such outdated filename restrictions, I guess we should extend them to all platforms to ensure cross-platform compatibility.

preloading a string that contains the reserved filenames causes the editor to hang indefinitely

Tests:
var Test = preload("Con")
var Test = preload("res://Con")

I'm really sorry but I'm not sure if i should open a new issue on cases like this

Well that's the issue I referenced above, so no, no need to reopen a new one.

@akien-mga thank you

Naming the root node as Con and saving it also hangs the editor indefinitely

For your information, I have written information on file name support in applications. The page refers to a "MakeFilename" method I wrote for C# and Java; however, as you can see by its implementation, avoiding problematic file names is anything but trivial.

For Windows in particular, see "Naming Files, Paths, and Namespaces" on docs.microsoft.com.

As said by peteroupc, windows doesn't allow:

  • CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.
  • It also doesn't allow any of above followed by a period ..
  • Case insensitivity of Windows also needs to be kept in mind.

I was planning on making a PR with these in mind but I was wondering if and where I should store this list. Should I just,

  1. Have it inside the is_valid_filename() function or
  2. As member part of ustring or
  3. Make a new separate file or
  4. Setting called reserved_names?
Was this page helpful?
0 / 5 - 0 ratings