From 9baa1cfdaa5b1da242f8b7b90b46e177ce482c38 Mon Sep 17 00:00:00 2001 From: David Lee Date: Wed, 18 Jun 2025 11:05:23 -0500 Subject: [PATCH 1/2] fix(removeBOM): updated the removeBOM method to actually remove the BOM characters instead of trimming whitespace --- src/utils.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 6783633..734f2c5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -47,14 +47,22 @@ export function addAlertsToList( export function removeBOM(chunk: string): string { // strip utf-8 BOM: see https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8 - const dataBuffer = Buffer.from(chunk) - if ( - dataBuffer.length > 2 && - dataBuffer[0] === 0xef && - dataBuffer[1] === 0xbb && - dataBuffer[2] === 0xbf - ) { - chunk = chunk.trimStart() + // Handle Buffer input + if (Buffer.isBuffer(chunk)) { + // Check for BOM in buffer + if (chunk.length > 2 && chunk[0] === 0xef && chunk[1] === 0xbb && chunk[2] === 0xbf) { + // Return buffer without BOM + return chunk.slice(3); + } + + return chunk; } - return chunk + + // Check for BOM in string and remove if present + if (typeof chunk === 'string' && chunk.charCodeAt(0) === 0xfeff) { + return chunk.substring(1); + } + + // For any other type, return as is + return chunk; } From 0e8bf31cfa9b2447d1ee6876ea043cc065d0abd4 Mon Sep 17 00:00:00 2001 From: David Lee Date: Wed, 18 Jun 2025 11:16:38 -0500 Subject: [PATCH 2/2] refactor(removeBOM): fix formatting issues --- src/utils.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 734f2c5..7b4c036 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -50,19 +50,24 @@ export function removeBOM(chunk: string): string { // Handle Buffer input if (Buffer.isBuffer(chunk)) { // Check for BOM in buffer - if (chunk.length > 2 && chunk[0] === 0xef && chunk[1] === 0xbb && chunk[2] === 0xbf) { + if ( + chunk.length > 2 && + chunk[0] === 0xef && + chunk[1] === 0xbb && + chunk[2] === 0xbf + ) { // Return buffer without BOM - return chunk.slice(3); + return chunk.slice(3) } - return chunk; + return chunk } // Check for BOM in string and remove if present - if (typeof chunk === 'string' && chunk.charCodeAt(0) === 0xfeff) { - return chunk.substring(1); + if (typeof chunk === "string" && chunk.charCodeAt(0) === 0xfeff) { + return chunk.substring(1) } // For any other type, return as is - return chunk; + return chunk }