瀏覽代碼

Update text.js

Lutz Roeder 3 年之前
父節點
當前提交
b4e4e3fa3c
共有 1 個文件被更改,包括 5 次插入2 次删除
  1. 5 2
      source/text.js

+ 5 - 2
source/text.js

@@ -133,8 +133,11 @@ text.Decoder.Utf8 = class {
                     if (c3 >= 0x80 && c3 <= 0xBF) {
                         const c4 = this.buffer[this.position + 2];
                         if (c4 >= 0x80 && c4 <= 0xBF) {
-                            this.position += 3;
-                            return String.fromCodePoint(((c & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F));
+                            const codePoint = ((c & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F);
+                            if (codePoint <= 0x10ffff) {
+                                this.position += 3;
+                                return String.fromCodePoint(codePoint);
+                            }
                         }
                     }
                 }