Skip to content

Attachment Names

File names copied and pasted from Windows, a browser, Office or a chat often carry characters that look normal but are not: typographic dashes and quotes, tabs, non-breaking spaces, zero-width characters, accents split in two (the way macOS stores them)... These names break scripts, deploys, storage providers and searches, and a file that should be a new version of an attachment becomes a separate attachment because its name differs by one invisible character.

Clarive can check the names of the files attached to topics against a set of rules. It never refuses an upload: it proposes a clean name instead, and asks whether the file is a new version of an attachment with a similar name.

Turning it on

The check is off until an administrator switches it on in Administration > System > General Settings, tab Attachments:

  • Check the characters of attachment names: switches the check on for every attachment field that uses the global rules. No restart is needed.
  • Attachment name rules: the global rules, drawn under the checkbox. They start with every built-in rule on, so switching the check on is enough to try it. While the check is off they are greyed out and can't be edited, but each rule keeps its state and applies again as it was when the check is switched back on. Try a name works even while the check is off.

Rules

The rules are edited in three parts:

  • Built-in rules: a switch each, with what it does and an example. Switch off the ones you do not want.
  • Custom rules: a row each, with a Name, a Regular expression and its Replacement. An empty replacement removes what the expression finds, and $1...$9 in the replacement are its groups. A row with an expression the browser can't use is marked in red and left out. The arrows change the order, and Add an example adds one of the examples below to start from. Custom rules apply after the built-in ones, in their order.
  • Try a name: type or paste a file name and see at once which characters the rules don't allow, the name they propose and the rules that changed it. Nothing is saved: it is there to try the rules before you save them.

Write special characters in an expression as \uXXXX ([\u2013\u2014]), which works both in the browser and in the server.

Built-in rules

Rule In the text What it does
Composed accents (NFC) nfc Joins accents split in two (n + ~) into one character (ñ).
Typographic quotes quotes Turns typographic quotes (‘ ’ ‚ ′ ´, “ ” „ « ») into ' and ".
Typographic dashes dashes Turns typographic dashes and minus signs (‐ ‑ ‒ – — ― −) into -.
Tabs and unusual spaces spaces Turns tabs, line breaks and unusual spaces (non-breaking, thin, ideographic...) into a space, leaves one space between words and removes the spaces at the ends and before the extension.
Invisible characters invisible Removes zero-width characters, the byte order mark, soft hyphens and bidirectional marks.
Control characters control Removes control characters.
Characters Windows does not allow windows_reserved Turns " into ' and < > : / \ \| ? * into _, and removes the dots and spaces at the end, as Windows does not allow them.
Letters outside ASCII non_ascii Spells the letters outside ASCII in ASCII (á → a, ñ → n, ß → ss) and turns any other character (for example Chinese or Cyrillic letters) into _.

non_ascii is the strictest rule: it also changes names that are fine in most systems, such as Año.docx, which becomes Ano.docx. Switch it off if your users name files in Spanish or in another language with accents and your tools handle them.

A name the rules leave with no letter nor digit, such as a zero-width space followed by .txt, is called file, keeping its extension: file.txt.

Custom rule examples

Name Regular expression Replacement Turns Into
Repeated dots \.{2,} . foo...bar.txt foo.bar.txt
Copy suffix \s*-\s*[Cc]op(?:y\|ia)(\.[^.]*)$ $1 Foo - Copy.docx Foo.docx
Version in brackets \s*\[v(\d+)\] _v$1 foo bar [v2].txt foo bar_v2.txt
Spaces to underscores \s+ _ foo bar.txt foo_bar.txt

Put Version in brackets before Spaces to underscores: the other way round, foo bar [v2].txt gives foo_bar__v2.txt.

The rule list as text

The rules are kept as text, one rule per line, which is what the API, the CLI and the MCP tools read and write (config.attachment.names.rules). Each line is the name of a built-in rule (several can share a line, separated by spaces or commas) or a custom rule as Name | regex | replacement. The regex is everything between the first and the last |, so it may have alternatives (foo|bar); a replacement in double quotes keeps its spaces (" "). Blank lines and lines that start with # are left out. A line that is neither (an unknown rule name, a custom rule without its regex) is left out too: the settings screen warns of it, and the server writes it in its log.

nfc quotes dashes spaces invisible control windows_reserved
Repeated dots | \.{2,} | .
Version in brackets | \s*\[v(\d+)\] | _v$1

Per attachment field

The Attach files fieldlet of a form rule has its own setting, Attachment name rules:

  • Use the global rules (the default): the field follows the global settings.
  • Add these rules to the global ones: the field applies the global rules, when they are on, and then its own Name rules.
  • Use only these rules: the field applies only its own Name rules, even when the global check is off.
  • Do not check the names: the field takes any name.

Name rules shows up with Add these rules to the global ones and Use only these rules. It is the same editor as the global rules, with its own Try a name, which tries only the rules of the field, without the global ones.

Uploading a file

When a user attaches a file, the browser checks its name before sending it:

  1. If the name breaks a rule, a dialog shows it with the characters that are not allowed marked (the invisible ones by their code, such as U+200B) and proposes the clean name. The user can accept it or type another one; a name that still breaks the rules can't be uploaded, and Fix it cleans it.
  2. If the topic already has an attachment with a similar name, the dialog offers to upload the file as a new version of that attachment, or as a new file. This is asked even when the name breaks no rule.
  3. Skip this file leaves out that file only. When several files are uploaded at once, the questions come one after the other.

Whatever the answer, the chosen name becomes the name of the attachment. Uploading a file with the very name of an attachment of the topic is a new version of it, as always, and is not asked about.

Similar names

Two names are similar when they are the same once case, accents, spaces, punctuation and invisible characters are left aside: Report – Final.docx, report-final.docx and REPORT final.docx are similar. Letters of other alphabets count as letters, so names in Chinese or Cyrillic are only similar to names with the same letters.

In the server

The server applies the same rules to every upload: the topic page, the API (topic.upload_file, the CLI and the MCP tools) and the rule services that attach files. A name that breaks the rules there is never refused: the file is stored with the clean name, and topic.upload_file answers it in filename, with the name sent in renamed_from. When that happens on the topic page (an older browser tab, for example), the user is told which name the file was stored with. A name the topic already has is a new version of that attachment and keeps it.