Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/util/__test__/expand-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,44 @@ describe('expandTemplate', () => {
const result = await expandPrompt('No placeholders here.', tempDir, {});
expect(result).toBe('No placeholders here.');
});

it('preserves $$ in a variable value verbatim', async () => {
const result = await expandPrompt('Price: {{cost}}', tempDir, {
cost: '$$100',
});
expect(result).toBe('Price: $$100');
});

it('preserves $& in a variable value verbatim', async () => {
const result = await expandPrompt('Body: {{body}}', tempDir, {
body: 'foo $& bar',
});
expect(result).toBe('Body: foo $& bar');
});

it('preserves $` in a variable value verbatim', async () => {
const result = await expandPrompt('Body: {{body}}', tempDir, {
body: 'before $` after',
});
expect(result).toBe('Body: before $` after');
});

it("preserves $' in a variable value verbatim", async () => {
const result = await expandPrompt('Body: {{body}}', tempDir, {
body: "before $' after",
});
expect(result).toBe("Body: before $' after");
});

it('preserves mixed dollar-sign sequences across multiple variables', async () => {
const result = await expandPrompt(
'Cost: {{cost}}, body: {{body}}',
tempDir,
{
cost: '$$100',
body: 'regex $& match',
},
);
expect(result).toBe('Cost: $$100, body: regex $& match');
});
});
2 changes: 1 addition & 1 deletion src/util/expand-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function expandPrompt(
let result = await expandIncludes(template, basePath);

for (const [key, value] of Object.entries(variables)) {
result = result.replaceAll(`{{${key}}}`, value);
result = result.replaceAll(`{{${key}}}`, () => value);
}

return result;
Expand Down