How Teamwork.com handles file names with special characters

Operating systems have strict rules about file naming, and our code enforces those rules by removing or replacing problematic characters, handling reserved system file names, and applying custom sanitization options.

E.g.

  1. Remove non-text characters

    like <, >, :, ?, etc. Remove tabs (\t), newlines (\n or \r), and zero-width space characters.

  2. Optionally handle whitespace:

    • Leave spaces intact (default).

    • Remove excess spaces (more than one).

    • Remove all spaces.

  3. Character Check and Removal:

    • Our method checks the file name for illegal characters based on the provided options.

      • Replaces illegal characters ([<>:\"/|?*\\]) with underscores (_).

      • Removes zero-width space characters.

      • Removes tabs, newlines, and carriage returns as per the options.

  4. Check for Reserved File Names:

    • Windows has reserved file names (e.g., CON, AUX, LPT1), which cannot be used as file names.

    • If the sanitized file name matches one of these reserved names, an underscore is appended, and a warning is added.

  5. Handle Blank File Names:

    • If the file name becomes empty after sanitization, a default file name is generated using the current timestamp.