From 9952519ec5270532e15c743ce3491ec4d0c3c488 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:38:54 +0000 Subject: [PATCH 1/4] Initial plan From e4f3e05cc0086f7a5d7d3b0c0df5a02279d43cbc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:48:18 +0000 Subject: [PATCH 2/4] Fix single-byte encoder validation for null chars and byte-0 mappings Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- single-byte.js | 4 ++-- single-byte.node.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/single-byte.js b/single-byte.js index 5462587e..5a5a7596 100644 --- a/single-byte.js +++ b/single-byte.js @@ -69,7 +69,7 @@ function encode(s, m) { for (const len3 = len - 3; i < len3; i += 4) { const x0 = s.charCodeAt(i), x1 = s.charCodeAt(i + 1), x2 = s.charCodeAt(i + 2), x3 = s.charCodeAt(i + 3) // prettier-ignore const c0 = m[x0], c1 = m[x1], c2 = m[x2], c3 = m[x3] // prettier-ignore - if ((!c0 && x0) || (!c1 && x1) || (!c2 && x2) || (!c3 && x3)) return null + if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null x[i] = c0 x[i + 1] = c1 @@ -80,7 +80,7 @@ function encode(s, m) { for (; i < len; i++) { const x0 = s.charCodeAt(i) const c0 = m[x0] - if (!c0 && x0) return null + if (c0 === undefined) return null x[i] = c0 } diff --git a/single-byte.node.js b/single-byte.node.js index 2f68c9c2..9d02709b 100644 --- a/single-byte.node.js +++ b/single-byte.node.js @@ -70,7 +70,7 @@ function encode(s, m) { for (const len3 = len - 3; i < len3; i += 4) { const x0 = x[i], x1 = x[i + 1], x2 = x[i + 2], x3 = x[i + 3] // prettier-ignore const c0 = m[x0], c1 = m[x1], c2 = m[x2], c3 = m[x3] // prettier-ignore - if (!(c0 && c1 && c2 && c3) && ((!c0 && x0) || (!c1 && x1) || (!c2 && x2) || (!c3 && x3))) return null // prettier-ignore + if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null x[i] = c0 x[i + 1] = c1 x[i + 2] = c2 @@ -80,7 +80,7 @@ function encode(s, m) { for (; i < len; i++) { const x0 = x[i] const c0 = m[x0] - if (!c0 && x0) return null + if (c0 === undefined) return null x[i] = c0 } From 87dde53fba8338583ae5c630119e27fb652a0397 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:52:22 +0000 Subject: [PATCH 3/4] Add prettier-ignore comments for consistency Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- single-byte.js | 2 +- single-byte.node.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/single-byte.js b/single-byte.js index 5a5a7596..2d9f7f35 100644 --- a/single-byte.js +++ b/single-byte.js @@ -69,7 +69,7 @@ function encode(s, m) { for (const len3 = len - 3; i < len3; i += 4) { const x0 = s.charCodeAt(i), x1 = s.charCodeAt(i + 1), x2 = s.charCodeAt(i + 2), x3 = s.charCodeAt(i + 3) // prettier-ignore const c0 = m[x0], c1 = m[x1], c2 = m[x2], c3 = m[x3] // prettier-ignore - if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null + if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null // prettier-ignore x[i] = c0 x[i + 1] = c1 diff --git a/single-byte.node.js b/single-byte.node.js index 9d02709b..21c0f201 100644 --- a/single-byte.node.js +++ b/single-byte.node.js @@ -70,7 +70,7 @@ function encode(s, m) { for (const len3 = len - 3; i < len3; i += 4) { const x0 = x[i], x1 = x[i + 1], x2 = x[i + 2], x3 = x[i + 3] // prettier-ignore const c0 = m[x0], c1 = m[x1], c2 = m[x2], c3 = m[x3] // prettier-ignore - if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null + if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null // prettier-ignore x[i] = c0 x[i + 1] = c1 x[i + 2] = c2 From 2542ebdbf01c011c7c21428b370a932a77cbb8a8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 17:10:29 +0000 Subject: [PATCH 4/4] Revert "Fix single-byte encoder validation" - original logic was correct The original validation check (!c0 && x0) is correct and intentional: - It detects when a non-zero character (x0 > 0) tries to map to byte 0 - This is important because in some encodings (windows-1250, windows-1252, x-user-defined), character U+0080 maps to byte 0, which should be rejected since byte 0 is reserved for null - The check correctly allows charCode 0 to map to byte 0 since (!0 && 0) = false My previous change broke this by only checking for undefined, which allowed non-zero characters to incorrectly map to byte 0. Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- single-byte.js | 4 ++-- single-byte.node.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/single-byte.js b/single-byte.js index 2d9f7f35..5462587e 100644 --- a/single-byte.js +++ b/single-byte.js @@ -69,7 +69,7 @@ function encode(s, m) { for (const len3 = len - 3; i < len3; i += 4) { const x0 = s.charCodeAt(i), x1 = s.charCodeAt(i + 1), x2 = s.charCodeAt(i + 2), x3 = s.charCodeAt(i + 3) // prettier-ignore const c0 = m[x0], c1 = m[x1], c2 = m[x2], c3 = m[x3] // prettier-ignore - if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null // prettier-ignore + if ((!c0 && x0) || (!c1 && x1) || (!c2 && x2) || (!c3 && x3)) return null x[i] = c0 x[i + 1] = c1 @@ -80,7 +80,7 @@ function encode(s, m) { for (; i < len; i++) { const x0 = s.charCodeAt(i) const c0 = m[x0] - if (c0 === undefined) return null + if (!c0 && x0) return null x[i] = c0 } diff --git a/single-byte.node.js b/single-byte.node.js index 21c0f201..2f68c9c2 100644 --- a/single-byte.node.js +++ b/single-byte.node.js @@ -70,7 +70,7 @@ function encode(s, m) { for (const len3 = len - 3; i < len3; i += 4) { const x0 = x[i], x1 = x[i + 1], x2 = x[i + 2], x3 = x[i + 3] // prettier-ignore const c0 = m[x0], c1 = m[x1], c2 = m[x2], c3 = m[x3] // prettier-ignore - if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return null // prettier-ignore + if (!(c0 && c1 && c2 && c3) && ((!c0 && x0) || (!c1 && x1) || (!c2 && x2) || (!c3 && x3))) return null // prettier-ignore x[i] = c0 x[i + 1] = c1 x[i + 2] = c2 @@ -80,7 +80,7 @@ function encode(s, m) { for (; i < len; i++) { const x0 = x[i] const c0 = m[x0] - if (c0 === undefined) return null + if (!c0 && x0) return null x[i] = c0 }