Encoding error or invisible character: two different diagnoses

Topic illustration for the article: Encoding error or invisible character: two different diagnoses
Practical illustration for this guide

The text “Привет” does not hide a secret space between letters. It usually represents UTF-8 bytes decoded with the wrong encoding. A character cleaner cannot repair that cause; recovery starts with the original bytes and the correct decoder.

Open the cleaner for a separate character check

Bytes and code points are different layers

A file stores bytes. An encoding maps those bytes to Unicode. After successful decoding, an application handles code points. ZWSP U+200B exists at the second layer; mojibake appears when the first transition was wrong.

U+FFFD records a failed decode

The replacement character � means a decoder encountered an invalid sequence. If that result was saved over the source, original bytes may be unrecoverable. Make a binary copy before testing any conversion.

A BOM is not a universal label

In UTF-8, a BOM is EF BB BF at the beginning. Some software treats it as a hint and some formats reject it. U+FEFF inside an already decoded string is a separate observation. Add or remove it only when the format requires that choice.

Start with a small evidence bundle

Keep the source file, declared encoding, initial bytes in hex and expected text. Open a copy with an explicit decoder. If letters recover, the issue was encoding. If U+200B remains, it is now a character-level problem.

Do not re-encode visible garbage by guesswork

An encode/decode trick may repair one sample and double-corrupt another. Run heuristics only on copies, report confidence and log transformations. On the web, use UTF-8 with a correct Content-Type.

Fix the first incorrect read

Correct the exporter, HTTP header, database driver or importer. Repeat the route from original bytes and compare a known string. Replacing every visible “Д or “Ñ” merely hides symptoms and damages legitimate content.

Two control samples

The first string is mojibake and requires the original byte path. The second contains a real U+200B visible in its code-point list. Treating both with one Clean button would be a design error.

const mojibake = "Привет";
const hidden = "order\u200B42";
console.log([...hidden].map(c => c.codePointAt(0).toString(16)));
// Decode bytes with the known source encoding; never guess on the only copy.

Evidence to preserve

  1. Original file without resaving.
  2. A hex sample around the failure.
  3. Declared encoding and HTTP headers.
  4. Exporter version.
  5. Expected text confirmed by the data owner.

Open the cleaner

Sources and specifications

Related guides

Author: Mykola. When original bytes are gone, this guide does not promise magical recovery; it helps prevent further loss.