From f4d254c513152d1694051307f611cd8be2fc0f68 Mon Sep 17 00:00:00 2001 From: Michael Gissing Date: Wed, 4 Sep 2024 13:12:29 +0200 Subject: [PATCH] fix: producer must not replace placeholder in source string --- lib/producer.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/producer.ts b/lib/producer.ts index 76759cfa..212569a9 100644 --- a/lib/producer.ts +++ b/lib/producer.ts @@ -37,14 +37,25 @@ function discoverPlaceholder( binaryBuffer: Buffer, searchString: string, padder: string, + searchOffset: number = 0, ): Placeholder | NotFound { const placeholder = Buffer.from(searchString); - const position = binaryBuffer.indexOf(placeholder); + const position = binaryBuffer.indexOf(placeholder, searchOffset); if (position === -1) { return { notFound: true }; } + // reject source code literal if it occurs first in binary + if (binaryBuffer[position - 1] === 39 /* ascii for ' APOSTROPHE */) { + return discoverPlaceholder( + binaryBuffer, + searchString, + padder, + position + placeholder.length, + ); + } + return { position, size: placeholder.length, padder }; }