Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打出不在 Unicode 基础多文本平面(Unicode 点位超过 U+FFFF)的字符时,中间的答案提示显示异常 #10

Closed
3TUSK opened this issue Jul 12, 2024 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@3TUSK
Copy link

3TUSK commented Jul 12, 2024

如下图。

Screen Shot 2024-07-11 at 6 40 04 PM

随便打点什么「𰻝𰻝面」的「𰻝」(U+30EDD)也可以观察到一样的问题。

Chromium 内核版本 125.0.6422.112。

疑似是强行显示一对 surrogate pair 的结果。估计是什么库没处理对 UTF-16……

@SkyEye-FAST SkyEye-FAST added the bug Something isn't working label Jul 12, 2024
@SkyEye-FAST
Copy link
Owner

什么风把您吹来了.jpg

大概看了一下,这是因为JavaScript中遍历#inputBox.val()的时候按每16 bit遍历,而BMP之外的代理对就被硬拆成了两个字符。例如“𰻝”(U+30EDD),UTF-16中编码为0xD883 0xDEDD,这里就会被拆成0xD8830xDEDD

    $(".box").each(function (index) {
        const $box = $(this);
        const userInput = input[index];
        const correctChar = translation[index];

        $box.text(userInput || "");

        if (!userInput) {
            $box.css("background-color", "#9ca3af25");
        } else if (userInput === correctChar) {
            $box.css("background-color", "#79b851");
        } else if (translation.includes(userInput)) {
            $box.css("background-color", "#f3c237");
        } else {
            $box.css("background-color", "#9ca3af25");
        }
    });

实际上简体中文语言文件里没有BMP以外的字符,但是为了防止在酒吧里点炒饭,还是换用Array.from修一下罢。

SkyEye-FAST added a commit that referenced this issue Jul 12, 2024
@SkyEye-FAST
Copy link
Owner

现在已经修复了Unihan字符的问题,但是Emoji中还带U+200D没法正常组合……

@AlPha5130
Copy link

现在已经修复了Unihan字符的问题,但是Emoji中还带U+200D没法正常组合……

你需要Intl.Segmenter

SkyEye-FAST added a commit that referenced this issue Jul 12, 2024
@SkyEye-FAST
Copy link
Owner

Intl.Segmenter分隔字符后能够正常显示,但是没法输入大型Emoji。

破案了,是初始的maxlength不够长导致的。事实上现在已经不需要初始设置maxlength了。我是唇笔.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants