You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2024/10/24 22:36:00 UTC

[jira] [Updated] (IO-860) Missing reserved filenames for Windows in FileSystem.WINDOWS (superscript digits for COM and LPT)

     [ https://issues.apache.org/jira/browse/IO-860?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated IO-860:
-------------------------------
    Summary: Missing reserved filenames for Windows in FileSystem.WINDOWS (superscript digits for COM and LPT)   (was: Missing reserved filenames for Windows in FileSystem.java (superscript digits for COM and LPT) )

> Missing reserved filenames for Windows in FileSystem.WINDOWS (superscript digits for COM and LPT) 
> --------------------------------------------------------------------------------------------------
>
>                 Key: IO-860
>                 URL: https://issues.apache.org/jira/browse/IO-860
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.17.0
>            Reporter: Stefan Feenstra
>            Assignee: Gary D. Gregory
>            Priority: Major
>
> Per Microsoft documentation, the following filenames are also reserved filenames: LPT¹, LPT², LPT³, COM¹, COM² and COM³.
> As far as I can tell, only the non-superscript filenames are marked as illegal in the FileSystem.WINDOWS enum. These six filenames should also be added as reserved filenames, as they can not be used for regular files. (e.g. trying to create a file called COM³ will fail).
>  
> Quote from the [microsoft documentation|https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#file-and-directory-names]:
> {code:java}
> Windows recognizes the 8-bit ISO/IEC 8859-1
>  superscript digits ¹, ², and ³ as digits and treats them as valid parts
>  of COM# and LPT# device names, making them reserved in every directory. {code}
> Testing code to reproduce: (there should be no output)
> {code:java}
> import org.apache.commons.io.FileSystem;
> public class FilenameTest {
>     public static void main(String[] args) {
>         char[] digitsWithSuperScript = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '¹', '²', '³'};
>         for (String filenamesPrefix : new String[]{"LPT", "COM"}) {
>             for (char digit : digitsWithSuperScript) {
>                 final String filename = filenamesPrefix + digit;
>                 checkFilename(filename, true);
>                 // Base filename should be reserved
>                 checkFilename(filename + ".tar.gz", true);
>                 // Extensions should be ignored
>                 checkFilename(filename + ".txt", true);
>                 // Non-extension suffixes are ok.
>                 checkFilename(filename + "additional_text", false);
>             }
>         }
>         for (String reservedFileName : new String[]{"CON", "PRN", "AUX", "NUL", "CONIN$", "CONOUT$"}) {
>             // Base filename should be reserved
>             checkFilename(reservedFileName, true);
>             // Extensions should be ignored
>             checkFilename(reservedFileName + ".tar.gz", true);
>             // Non-extension suffixes are ok.
>             checkFilename(reservedFileName + "additional_text", false);
>         }
>     }
>     static void checkFilename(String filename, boolean isReserved) {
>         boolean isReservedAccordingToAPI = FileSystem.WINDOWS.isReservedFileName(filename);
>         if (isReserved != isReservedAccordingToAPI) {
>             if (isReserved) {
>                 System.out.printf("'%s' is reserved according to the spec but not according to FileSystem.isReservedFileName%n", filename);
>             } else {
>                 System.out.printf("'%s' is not reserved according to the spec but is according to FileSystem.isReservedFileName%n", filename);
>             }
>         } else {
>             // Spec and API match
>         }
>     }
> }{code}
>  
> Link to relevant code:
> [https://github.com/apache/commons-io/blob/ec0fd2c98f0bf94d6d87c6adf237430e606e2e23/src/main/java/org/apache/commons/io/FileSystem.java#L91C16-L92C116]
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)