What are BiDi characters and why do they cause glitches?
Bidirectional (BiDi) characters are hidden markers like the left-to-right mark (U+200E) and right-to-left mark (U+200F). They are essential for handling mixed-direction text — for example, a paragraph containing both English and Arabic.
However, when these markers are copied "out of context" — such as copying a single English word from a multilingual site — they remain embedded in the text. This causes your cursor to jump to the wrong side of a word, makes highlighting text nearly impossible, and can even flip the displayed order of punctuation like periods and parentheses. Like all invisible characters, they have no glyph, so you can't find them by looking.
Why are BiDi characters dangerous in code?
BiDi markers are particularly dangerous for developers. If a directional override ends up inside a string or an identifier, the code can display one way while compiling another. This is the basis of the "Trojan Source" attack (CVE-2021-42574): override characters such as U+202E reorder what reviewers see on screen, so a line that looks like a harmless comment can actually contain executing logic. That's why many code editors and GitHub now warn about BiDi characters in diffs — and why pasted snippets should be sanitized before committing. To audit a snippet without altering it first, the hidden character checker lists every directional control it finds by code point and count, leaving the text as it is.
Our tool identifies every directional control character — U+200E, U+200F, the Arabic letter mark U+061C, the embedding and override set U+202A through U+202E, and the newer isolates U+2066 through U+2069 — and strips them completely, "resetting" the text to the default direction of your destination editor. See the full invisible Unicode characters list for every code point covered, or the zero-width space remover for the other big family of invisible troublemakers.
Worked example: a Trojan Source "stretched string"
The Trojan Source researchers published examples of this pattern, tracked as CVE-2021-42574. Below, each invisible control is written as a bracketed name so you can see where it sits. This is the order the characters are stored in the file, which is what the JavaScript engine reads:
var accessLevel = "user";
if (accessLevel != "user[RLO U+202E] [LRI U+2066]// Check if admin[PDI U+2069] [LRI U+2066]") {
console.log("You are an admin.");
}The right-to-left override (U+202E) and the isolates (U+2066, U+2069) tell the renderer to lay out the end of that string in reverse. On screen, a reviewer sees what looks like a check against "user" followed by an ordinary // Check if admin comment. In reality the comment text is inside the string literal, the comparison is against a longer string that never matches, and every user takes the admin branch. The display rules that make this possible are the explicit-formatting rules of the Unicode Bidirectional Algorithm (UAX #9).
Paste a line like this into the cleaner with the BiDi controls toggle on (it is on in every preset except Markdown to Text) and the report lists U+202E, U+2066 and U+2069 by name. The cleaned output shows the string in stored order, so the hidden comment is plainly part of the literal. Treat that as a reason to reject the code, not just to clean it.