解析器报错、Webhook 签名校验失败以及 SQL 查询未命中,往往源于在终端模拟器或代码编辑器中渲染效果完全相同(甚至完全不可见)的特殊字符。假设从文档门户或即时通讯软件中复制了一段环境变量,肉眼看起来与 api_key=prod 完全一致:
Visual rendering: api_key=prod
String.length: 14 (expected 12)
UTF-8 byte length: 19 bytes (expected 12 bytes)
将这段长度为 14 的字符串放入 Unicode 字符检测器中运行,就能立即揪出潜藏在看似纯 ASCII 文本中的三处异常:开头的字节序标记(<BOM>)、顶替拉丁字母 a 的西里尔同形字,以及夹在中间的零宽空格(<ZWSP>):
[
{
"index": 0,
"badge": "<BOM>",
"codePoint": "U+FEFF",
"name": "ZERO WIDTH NO-BREAK SPACE",
"category": "Cf (Format)",
"block": "Arabic Presentation Forms-B",
"utf8Hex": "EF BB BF",
"utf16BE": "FE FF",
"utf16LE": "FF FE",
"warning": "Invisible zero-width format character"
},
{
"index": 1,
"glyph": "а",
"codePoint": "U+0430",
"name": "CYRILLIC SMALL LETTER A",
"category": "Ll (Lowercase Letter)",
"block": "Cyrillic",
"utf8Hex": "D0 B0",
"utf16BE": "04 30",
"utf16LE": "30 04",
"warning": "Confusable homoglyph for Latin U+0061 ('a')"
},
{
"index": 2,
"glyph": "p",
"codePoint": "U+0070",
"name": "LATIN SMALL LETTER P",
"category": "Ll (Lowercase Letter)",
"block": "Basic Latin",
"utf8Hex": "70",
"utf16BE": "00 70",
"utf16LE": "70 00",
"warning": null
},
{
"index": 8,
"badge": "<ZWSP>",
"codePoint": "U+200B",
"name": "ZERO WIDTH SPACE",
"category": "Cf (Format)",
"block": "General Punctuation",
"utf8Hex": "E2 80 8B",
"utf16BE": "20 0B",
"utf16LE": "0B 20",
"warning": "Invisible zero-width format character"
}
]
此外,本检测器还能清晰解释为什么复合码位 Emoji 在不同运行时环境中会报告截然不同的字符串长度。例如检测单个视觉可见的程序员 Emoji 👨💻 时,工具会展示出它实际上是由 <ZWJ>(U+200D)连接的 3 个标量码位组成,在 JavaScript 中占用 5 个 UTF-16 代码单元,而在 UTF-8 中占用 11 个字节:
Grapheme clusters (UAX #29): 1 -> [ "👨💻" ]
Unicode scalar code points: 3 -> U+1F468 (Man) + U+200D (<ZWJ>) + U+1F4BB (Laptop)
UTF-16 code units (.length): 5 -> D83D DC68 + 200D + D83D DCBB
UTF-8 encoded bytes: 11 -> F0 9F 91 A8 + E2 80 8D + F0 9F 92 BB