From ea9b207b0ba881a70f81cc5b1ab35e7fc9b5a844 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sat, 23 Jun 2018 16:21:04 +0000 Subject: [PATCH] Fixed JavaScript UTF-16 logic to handle a rare erroneous edge case. --- javascript/qrcodegen-demo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/qrcodegen-demo.js b/javascript/qrcodegen-demo.js index 2712985..191cc9a 100644 --- a/javascript/qrcodegen-demo.js +++ b/javascript/qrcodegen-demo.js @@ -109,7 +109,7 @@ function redrawQrCode() { var c = str.charCodeAt(i); if (c < 0xD800 || c >= 0xE000) continue; - else if (0xD800 <= c && c < 0xDC00) { // High surrogate + else if (0xD800 <= c && c < 0xDC00 && i + 1 < str.length) { // High surrogate i++; var d = str.charCodeAt(i); if (0xDC00 <= d && d < 0xE000) // Low surrogate