Skip to main content

Hidden Characters

Remove BiDi & Directional Control Characters

By Issaaf Kattan · Updated

Paste your text to clean it

Your text

No text handy? Try:

Cleaned text

Your text never leaves this browser. How we know

Same words · No AI rewriting · No content logging

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.

Common questions

Frequently asked questions

What are BiDi control characters?

They are invisible Unicode characters that control the direction text is displayed in: the left-to-right mark (U+200E), right-to-left mark (U+200F), the embedding and override controls (U+202A through U+202E), and the newer isolate controls (U+2066 through U+2069). They exist so mixed-direction text — English with Arabic or Hebrew — renders correctly, but copied out of context they wreak havoc.

How do I remove BiDi characters from text?

Paste the text into a cleaner that targets the directional ranges, like CleanPastedText. It matches U+200E, U+200F, U+061C, U+202A–U+202E, and U+2066–U+2069, deletes every occurrence, and reports the count under 'Directional markers removed'. This resets the text to follow the natural direction of its characters and your editor's default.

Why does my cursor jump around when I select or edit text?

A stray directional mark is usually the cause. When a hidden right-to-left mark sits inside left-to-right text, the editor renders part of the line in the opposite direction: the cursor appears to jump to the wrong side, highlighting selects unexpected ranges, and punctuation like periods or parentheses displays in the wrong place. Removing the mark fixes all of it.

What is a Trojan Source attack?

A technique (CVE-2021-42574, published in 2021) that uses BiDi override characters to make source code display differently than it compiles. A reviewer sees an innocent-looking line while the compiler executes reordered logic — for example, code that appears to be inside a comment but actually runs. Stripping directional controls from pasted code snippets neutralizes the attack.

Will removing BiDi marks break my Arabic or Hebrew text?

Generally no. Arabic and Hebrew letters carry inherent right-to-left directionality, so normal text renders correctly without any control characters — the Unicode BiDi algorithm handles it automatically. Explicit marks are only needed for edge cases like neutral punctuation at direction boundaries. The 'What changed' report shows exactly how many marks were removed so you can verify the result.

Continue reading

Related guides & tools