From: Jesse Tane Date: Sun, 16 Aug 2015 22:33:56 +0000 (-0400) Subject: utf8Slice: don't replace the replacement character X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=174947d4bbf6d08b1294b14b3b9cb95ae25011cf;p=buffer.git utf8Slice: don't replace the replacement character --- 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)