From ab7afb4135f90e488d9b6ee733862be31f7827b0 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 08:55:50 +0000 Subject: [PATCH] fix: revert to direct Buffer.from() for proper type handling Co-Authored-By: shryas.londhe@gmail.com --- packages/helpers/src/input-generators.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/helpers/src/input-generators.ts b/packages/helpers/src/input-generators.ts index 8f06de6a..b3cdf8b8 100644 --- a/packages/helpers/src/input-generators.ts +++ b/packages/helpers/src/input-generators.ts @@ -56,7 +56,7 @@ function findSelectorInCleanContent( positionMap: Map, ): { selector: string; originalIndex: number } { // Convert cleanContent to Buffer to ensure consistent type handling - const cleanBuffer = Buffer.from(cleanContent.buffer); + const cleanBuffer = Buffer.from(cleanContent); // First build a clean string without soft line breaks const cleanString = cleanBuffer.toString(); @@ -190,7 +190,7 @@ function getAdjustedSelector( */ function removeSoftLineBreaks(body: Uint8Array): { cleanContent: Uint8Array; positionMap: Map } { // Convert to Buffer for consistent handling - const bodyBuffer = Buffer.from(body.buffer); + const bodyBuffer = Buffer.from(body); const result: number[] = []; const positionMap = new Map(); // clean -> original let i = 0; @@ -345,7 +345,7 @@ export function generateEmailVerifierInputsFromDKIMResult( while (readPos < contentWithoutBreaks.length) { // Handle multi-byte UTF-8 sequences if (readPos < contentWithoutBreaks.length - 8 && contentWithoutBreaks[readPos] === 61) { // '=' character - const slice = Buffer.from(contentWithoutBreaks.slice(readPos, readPos + 9).buffer); + const slice = Buffer.from(contentWithoutBreaks.slice(readPos, readPos + 9)); const str = slice.toString(); const qpMatch = str.match(/^=([0-9A-F]{2})=([0-9A-F]{2})=([0-9A-F]{2})/); if (qpMatch) { @@ -362,7 +362,7 @@ export function generateEmailVerifierInputsFromDKIMResult( // Handle single-byte QP sequences if (readPos < contentWithoutBreaks.length - 2 && contentWithoutBreaks[readPos] === 61) { - const nextTwo = Buffer.from(contentWithoutBreaks.slice(readPos + 1, readPos + 3).buffer).toString(); + const nextTwo = Buffer.from(contentWithoutBreaks.slice(readPos + 1, readPos + 3)).toString(); if (/[0-9A-F]{2}/.test(nextTwo)) { decodedContent[writePos++] = parseInt(nextTwo, 16); readPos += 3;