Unicode normalization: why identical letters can be different strings

Topic illustration for the article: Unicode normalization: why identical letters can be different strings
Practical illustration for this guide

Two labels reading “Café” once behaved differently in search. One used U+00E9; the other used e followed by U+0301. Both are valid Unicode. The mismatch was neither a hidden watermark nor a font defect, but two representations of the same written text.

Load a decomposed-letter example

NFC and NFD preserve canonical meaning

NFD decomposes characters into a base and combining marks; NFC composes them where possible. Canonically equivalent strings represent the same text, yet binary equality still sees different code-point sequences until both sides use the same normalization form.

NFKC and NFKD are broader transformations

Compatibility forms also fold presentation and typographic variants. That can help a deliberately designed search key, but may erase a distinction needed in mathematics, product codes or a user interface. NFKC is not automatically better because it changes more.

Normalize at a documented boundary

Choose an input boundary: before storing a username, while building a search index or before comparing keys. If some records are normalized on write and others only on lookup, subtle duplicates accumulate. Name one form in the data contract and use it consistently.

Do not silently rewrite exact data

Passwords, signatures, hashes, signed documents and byte-exact identifiers must not be retrospectively normalized. A changed sequence is changed data. For migration, retain the original, the candidate normalized value and a collision report.

Normalization is not invisible-character removal

NFC does not promise to remove ZWSP, BiDi controls or C0 characters. A combining mark may have no advance width on its own and still be essential to spelling. Separate the goals of comparison, display and filtering before selecting an operation.

Test collisions, not just happy paths

Two existing records may collapse to the same normalized key. Count those pairs before migration, decide which record owns the key and test languages that rely heavily on combining marks. Success means stable lookup without losing the source spelling.

JavaScript check

The two strings look the same but strict equality is initially false. NFC makes them comparable. Listing code points before and after keeps the decision observable.

const composed = "caf\u00E9";
const decomposed = "cafe\u0301";
console.log(composed === decomposed); // false
console.log(composed.normalize("NFC") === decomposed.normalize("NFC")); // true

Before deployment

  1. Name the field and required form.
  2. Preserve original values.
  3. Find collisions on a copy.
  4. Test lookup, sorting and export.
  5. Keep normalization separate from deletion.

Open the cleaner

Sources and specifications

Related guides

Mykola wrote this guide to explain a testable mechanism, not to promise universal text purity. The data contract determines the form.