Skip to content

Commit 37a584a

Browse files
committed
fix: wrap command output in {% raw %} to prevent template interpretation
Command substitution output (!`cmd`) can contain {{ variable }} patterns that LiquidJS would interpret as template variables, causing unexpected prompts for missing variables. Wrapping in {% raw %}...{% endraw %} prevents this.
1 parent 82e5e31 commit 37a584a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/__snapshots__/snapshot.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ Process these files accordingly."
8585
exports[`Snapshot Tests Command substitution executes and inlines command output 1`] = `
8686
"Current date context:
8787
88+
8889
Test command output
8990
91+
9092
Please proceed with the task."
9193
`;
9294

src/imports.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ test("expandImports throws on missing file", async () => {
7171
test("expandImports executes command inline", async () => {
7272
const content = "Output: !`echo hello`";
7373
const result = await expandImports(content, testDir);
74-
expect(result).toBe("Output: hello");
74+
// Command output is wrapped in {% raw %} to prevent LiquidJS template interpretation
75+
expect(result).toBe("Output: {% raw %}\nhello\n{% endraw %}");
7576
});
7677

7778
test("expandImports handles command with arguments", async () => {
7879
const content = "!`echo one two three`";
7980
const result = await expandImports(content, testDir);
80-
expect(result).toBe("one two three");
81+
expect(result).toBe("{% raw %}\none two three\n{% endraw %}")
8182
});
8283

8384
test("expandImports handles multiple imports", async () => {
@@ -89,7 +90,7 @@ test("expandImports handles multiple imports", async () => {
8990
test("expandImports handles mixed file and command", async () => {
9091
const content = "File: @./simple.md Command: !`echo test`";
9192
const result = await expandImports(content, testDir);
92-
expect(result).toBe("File: Hello from simple.md Command: test");
93+
expect(result).toBe("File: Hello from simple.md Command: {% raw %}\ntest\n{% endraw %}");
9394
});
9495

9596
test("expandImports preserves content without imports", async () => {

src/imports.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,19 @@ async function processCommandInline(
761761
const stderr = result.stderr.toString().trim();
762762

763763
// Combine stdout and stderr (stderr first if both exist)
764+
let output: string;
764765
if (stderr && stdout) {
765-
return `${stderr}\n${stdout}`;
766+
output = `${stderr}\n${stdout}`;
767+
} else {
768+
output = stdout || stderr || "";
766769
}
767-
return stdout || stderr || "";
770+
771+
// Wrap in {% raw %}...{% endraw %} to prevent LiquidJS from interpreting
772+
// any template-like syntax (e.g., {{ variable }}) in command output
773+
if (output) {
774+
return `{% raw %}\n${output}\n{% endraw %}`;
775+
}
776+
return output;
768777
} catch (err) {
769778
throw new Error(`Command failed: ${command} - ${(err as Error).message}`);
770779
}

0 commit comments

Comments
 (0)