Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-860

Missing reserved file names in FileSystem.WINDOWS (superscript digits for COM and LPT)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.17.0
    • 2.18.0
    • Utilities
    • None

    Description

      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:

      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. 

      Testing code to reproduce: (there should be no output)

      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
              }
          }
      }

       

      Link to relevant code:

      https://github.com/apache/commons-io/blob/ec0fd2c98f0bf94d6d87c6adf237430e606e2e23/src/main/java/org/apache/commons/io/FileSystem.java#L91C16-L92C116

       

      Attachments

        Activity

          People

            ggregory Gary D. Gregory
            stefan.esq Stefan Feenstra
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: