Skip to content

Commit

Permalink
fix: producer must not replace placeholder in source string
Browse files Browse the repository at this point in the history
  • Loading branch information
faulpeltz committed Sep 4, 2024
1 parent 30af1d8 commit f4d254c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down

0 comments on commit f4d254c

Please sign in to comment.