Skip to content

Commit 1b8b89d

Browse files
cdervclaude
andcommitted
Add test for output-dir: ../dirname pattern
Add test case for when output-dir uses parent traversal to reference the project directory (e.g., project in "quarto-proj" with output-dir: "../quarto-proj"). This edge case was raised in PR review. The fix using resolve() correctly handles this pattern since resolve(dir, "../dirname") equals resolve(dir) when dirname is the current directory name. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fac0869 commit 1b8b89d

6 files changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project:
2+
type: default
3+
output-dir: ../output-dir-parent-ref
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This file should NOT be deleted when rendering with output-dir: ../output-dir-parent-ref
2+
This pattern references the project directory via parent traversal.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "Output Dir Parent Ref Test"
3+
format: html
4+
---
5+
6+
# Test Document
7+
8+
This document tests that `output-dir: ../output-dir-parent-ref` (referencing the project directory via parent traversal) does not delete the project directory.

‎tests/smoke/project/project-output-dir-safety.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ testOutputDirSafety("dot", null);
6262

6363
// Test 3: output-dir: _output (normal subdirectory case)
6464
testOutputDirSafety("subdir", "_output");
65+
66+
// Test 4: output-dir: ../dirname (parent traversal back to project dir)
67+
// This tests the case where output-dir references the project directory
68+
// via parent traversal (e.g., project in "quarto-proj", output-dir: "../quarto-proj")
69+
testOutputDirSafety("parent-ref", null);

‎tests/unit/path.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ unitTest("path - output-dir equivalence with resolve()", async () => {
176176
);
177177
}
178178

179+
// Parent traversal back to project dir should also be equivalent
180+
// e.g., project in "quarto-proj", output-dir: "../quarto-proj"
181+
const dirName = testDir.split(/[/\\]/).pop()!;
182+
const parentRef = `../${dirName}`;
183+
const resolvedParentRef = resolve(testDir, parentRef);
184+
assert(
185+
resolvedParentRef === resolve(testDir),
186+
`output-dir "${parentRef}" should resolve to project dir, got ${resolvedParentRef} vs ${resolve(testDir)}`,
187+
);
188+
179189
// Actual subdirectories should NOT be equivalent
180190
const subdir = "output";
181191
const resolvedSubdir = resolve(testDir, subdir);

0 commit comments

Comments
 (0)