From 174947d4bbf6d08b1294b14b3b9cb95ae25011cf Mon Sep 17 00:00:00 2001 From: Jesse Tane Date: Sun, 16 Aug 2015 18:33:56 -0400 Subject: [PATCH] utf8Slice: don't replace the replacement character --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 896ca4c..fe70d22 100644 --- a/index.js +++ b/index.js @@ -629,7 +629,7 @@ function utf8Slice (buf, start, end) { var i = start while (i < end) { var firstByte = buf[i] - var codePoint = 0xFFFD + var codePoint = null var bytesPerSequence = (firstByte > 0xEF) ? 4 : (firstByte > 0xDF) ? 3 : (firstByte > 0xBF) ? 2 @@ -676,8 +676,10 @@ function utf8Slice (buf, start, end) { } } - if (codePoint === 0xFFFD) { - // we generated an invalid codePoint so make sure to only advance by 1 byte + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD bytesPerSequence = 1 } else if (codePoint > 0xFFFF) { // encode to utf16 (surrogate pair dance) -- 2.34.1