Home/Text Analysis, List Comparison & Editing Tools/Invisible Whitespace & Zero-Width Space Cleaner

Invisible Whitespace & Zero-Width Space Cleaner

Detect, visualize, and strip hidden Unicode characters, zero-width spaces, BOM markers, and BiDi overrides in real time.

Hidden Artifacts
9found
Potential bugs detected
Security Risk
High Risk
ZWSP, BOM or BiDi present
Raw Payload Size
385bytes
369 characters
Cleaned Efficiency
23bytes saved
New size: 362 bytes

Raw Input & Diagnostic Visualizer

// Example Payload containing invisible zero-width bugs, BOM, and BiDi controls: const apiKey = "sk_live_[ZWSP]9834[BOM]12984";[BIDI] // Contains ZWSP + BOM + BiDi marker! const userRole = "admin[ZWNJ]"; // Trailing ZWNJ breaks direct string equality const priceLabel = "Total:[NBSP]$499.00"; // Non-breaking space prevents regex \s matches const rawNote = "Hello[ZWJ]World[WJ]Secure[SHY]Token[CJK-SP]Indented";

Colored badges highlight exact Unicode points that are otherwise 100% invisible on your screen.

Detected Character Breakdown
ZWSP1
ZWNJ1
ZWJ1
WJ1
BOM1
NBSP1
CJK-SP1
BIDI1
SHY1
Encoding: UTF-8 / Unicode100% Client-Side Inspection

Sanitization Engine & Output

Output Cleaned
Active Sanitization Rules

Understanding Zero-Width Characters and Invisible Whitespace Anomalies

Modern text processing relies heavily on Unicode, an expansive character encoding standard comprising over 149,000 discrete symbols. While Unicode enables worldwide multilingual software engineering, it also introduces dozens of invisible formatting markers, zero-width joiners, non-breaking spacers, and bidirectional control codes. When these non-printing characters find their way into source code, database queries, authentication credentials, or REST API payloads, they create silent failures that elude traditional visual debugging.

Because zero-width characters occupy zero visual width in standard user interfaces and text editors, a string such as "admin\u200B" appears completely identical to "admin" on screen. However, at the byte and binary level, their hash digests, memory representations, and string lengths differ completely. A strict equality check (userRole === "admin") evaluates to false, causing inexplicable logic bypasses, broken routing parameters, and corrupted JSON schemas.

Vulnerability 1

JSON & YAML Serialization Fails

Invisible Byte Order Marks (U+FEFF) and control characters at the beginning of payload strings cause parser crashes (e.g., Unexpected token at position 0).

Vulnerability 2

Database Key Mismatches

Zero-width characters inside unique columns or foreign keys lead to duplicate records, broken SQL indexing, and failed join lookups across relational tables.

Vulnerability 3

API Key & Hash Corruption

Secret API tokens, JWT signatures, and SHA-256 cryptographic hashes copied from formatted documentation frequently carry invisible NBSP characters that invalidate authentication.

Comprehensive Unicode Invisible & Special Whitespace Matrix

The reference table below catalogs the most prevalent invisible Unicode code points, their standard typographic intentions, and their typical software engineering failure modes:

Unicode CodeCharacter NameVisual AppearanceIntended Typographic RoleCommon Bug / Failure Mode
U+200BZero-Width Space (ZWSP)0px width (Invisible)Soft line-wrap break indicatorBreaks strict string comparisons, SQL WHERE matching, regex parsing
U+FEFFByte Order Mark / ZWNBSP0px width (Invisible)Byte endianness declaration in UTF-16Fatal JSON parse exceptions, shell script header compilation errors
U+00A0Non-Breaking Space (NBSP)1 standard space widthPrevents line breaks between paired wordsCLI command execution failures (e.g., command not found in Bash)
U+200CZero-Width Non-Joiner (ZWNJ)0px width (Invisible)Suppresses cursive ligatures in Persian/ArabicMismatches in URL slugs, slugification algorithms, and email addresses
U+200DZero-Width Joiner (ZWJ)0px width (Invisible)Combines multiple glyphs into single emojisUnexpected string length counts in SMS/Twitter character limits
U+202ERight-to-Left Override (RLO)0px width (Invisible)Reverses text visual rendering directionTrojan Source code obfuscation (disguises executable code as comments)
U+3000Ideographic Space2 standard spaces widthFull-width alignment in CJK typographyBreaks monospace tabular column alignment in terminal output

Cybersecurity Implications: Trojan Source Code Attacks and Steganography

In November 2021, Cambridge University researchers disclosed a critical vulnerability class known as Trojan Source (CVE-2021-42574). This attack vector exploits the Unicode Bidirectional (BiDi) Algorithm. Because compilers parse source tokens in linear logical order while code editors render characters according to directional overrides, attackers can construct source code that appears entirely harmless in human code review while compiling into malicious binary instructions.

Comment-Out Injection Attacks

By inserting a Right-to-Left Override (U+202E), an attacker can visually project executable exploit code inside what appears to be a multi-line code comment. The human reviewer sees only documentation, but the compiler executes the payload.

Zero-Width Fingerprinting (Steganography)

Whistleblower text and proprietary source leaks are frequently watermarked by internal systems that embed zero-width spaces (representing binary 0s) and zero-width joiners (representing binary 1s) to trace individual leakers invisibly.

Automated Sanitization in CI/CD Pipelines

To ensure non-printable Unicode characters never breach production repositories, software engineering teams should integrate pre-commit linters and automated regex sanitizers into GitHub Actions and GitLab CI stages:

# Strip all zero-width spaces, BOMs, and BiDi controls via Perl/Node regex:
$ node -e 'fs.writeFileSync("file.js", fs.readFileSync("file.js", "utf8").replace(/[\u200B-\u200D\uFEFF\u202A-\u202E]/g, ""))'

Programmatic Sanitization: JavaScript, Python, and SQL Snippets

Implement the following battle-tested snippets in your backend microservices to clean user input and sanitize external text streams automatically:

JavaScript / TypeScript
export function cleanText(str) {
  return str
    // Strip zero-width & BOM
    .replace(/[\u200B-\u200D\uFEFF\u2060]/g, "")
    // Normalize NBSP
    .replace(/[\u00A0\u202F]/g, " ")
    // Strip BiDi controls
    .replace(/[\u202A-\u202E]/g, "");
}
Python 3 (Regex)
import re

def sanitize_unicode(text: str) -> str:
    # Remove zero-width and BOM
    pattern = r'[\u200b-\u200d\ufeff\u2060]'
    cleaned = re.sub(pattern, '', text)
    # Replace non-breaking spaces
    return cleaned.replace('\u00a0', ' ')
PostgreSQL (SQL)
-- Clean column data in PostgreSQL
UPDATE user_records
SET email = REGEXP_REPLACE(
    email,
    '[\x{200B}\x{200C}\x{200D}\x{FEFF}]',
    '',
    'g'
)
WHERE email ~ '[\x{200B}\x{200C}\x{200D}\x{FEFF}]';

Frequently Asked Questions (FAQ)

What are zero-width spaces and why do they break code and JSON payloads?

Zero-width spaces (such as U+200B, U+200C, and U+200D) are non-printing Unicode characters that occupy zero horizontal pixels on a screen. While visually imperceptible, they contain discrete byte sequences that cause syntax errors in JSON parsers, break string equality checks in Python and JavaScript, corrupt JWT API keys, and fail database foreign key matching.

How does this tool detect hidden Byte Order Marks (BOM) and BiDi overrides?

The tool analyzes raw text streams byte-by-byte against the complete Unicode standard database, detecting UTF-8 Byte Order Marks (U+FEFF), Bidirectional overrides (U+202E, U+202A), and C0/C1 control codes that are frequently used in Trojan Source attacks to disguise malicious executable code.

What is the difference between standard spaces and Non-Breaking Spaces (NBSP)?

A standard ASCII space is represented by character byte 0x20 (U+0020). A Non-Breaking Space (NBSP, U+00A0) is a typographical entity created by Microsoft Word, Google Docs, and HTML entities ( ) to prevent automatic line wrapping. When pasted into terminal commands or CLI tools, NBSP produces unexpected syntax errors because compilers do not treat it as valid whitespace delimiter.

Is my text secure and private when using this online zero-width cleaner?

Yes, 100% of the Unicode inspection and cleaning logic executes purely inside your local browser runtime via client-side JavaScript. No text, source code, API keys, or database dumps are ever uploaded or transmitted to an external server.

Can zero-width spaces be used for malicious steganography or digital fingerprinting?

Yes. Malicious actors and enterprise watermarking systems encode binary data (such as user IDs or secret tokens) into invisible sequences of ZWSP (binary 0) and ZWNJ (binary 1). This tool uncovers all such hidden patterns instantly and provides complete sanitization.

What are BiDi Unicode Trojan Source attacks?

Trojan Source attacks (CVE-2021-42574) exploit Bidirectional (BiDi) Unicode control characters (like U+202E Right-to-Left Override) to alter the visual display order of source code in code editors so that comments appear as executable statements or vice versa, creating stealth vulnerabilities.

Found this tool helpful? Share it with others!

Share on Facebook
Share on X
Share on LinkedIn
Copy URL

Related & Complementary Utilities

Explore more privacy-first client-side web tools.