Fix quarto preview subdir/file.qmd crashing with doubled path#14150
Merged
Fix quarto preview subdir/file.qmd crashing with doubled path#14150
quarto preview subdir/file.qmd crashing with doubled path#14150Conversation
`quarto preview subdir/page.qmd` in a website project crashes with `readfile subdir\subdir\page.qmd`. The `projectPath` function was designed for output filenames (resolving relative to source directory via dirname+join), but was also called with the source path itself. When that source path was relative, dirname+join doubled the subdirectory. Split into two functions: `projectRelativeInput` for source paths (normalizes directly) and `projectOutputPath` for output filenames (preserves the dirname+join logic).
The FileInformationCacheMap (added in #13955) normalizes keys so that relative and absolute paths to the same file share one cache entry. This adds the test case that was missing from the original test suite.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Collaborator
Author
|
@cscheid tests are passing, and I think this is a change that make sense and solve the problem. I can now run preview correct. So if good to you, please merge and build a new prerelease. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
quarto preview subdir/page.qmdin a website project crashes withreadfile subdir\subdir\page.qmd— a doubled path.quarto renderworks fine.Root Cause
Preview makes two render calls:
renderFormats(receives the original relative path) thenrenderProject(normalizes to absolute). The first call creates a cachedExecutionTargetwithsource: "subdir/page.qmd". The second gets a cache hit with the stale relative source.projectPath()was designed for output filenames — it resolves relative paths viajoin(dirname(target.source), path).quarto-cli/src/command/render/render.ts
Lines 389 to 405 in 0f97e05
But then,
context.target.sourceitself is passed through this function.quarto-cli/src/command/render/render.ts
Line 414 in 0f97e05
When
target.sourcewas relative,dirname + joindoubled the subdirectory:projectPath(finalOutput!)is used correctly though — output filenames likepage.htmldo need thedirname + joinresolution.quarto-cli/src/command/render/render.ts
Line 424 in 0f97e05
Fix
Split
projectPathinto two functions with distinct responsibilities:projectRelativeInput(sourcePath)— for the source file path. UsesnormalizePathdirectly, which handles both relative and absolute paths, because ournormalizePathfunction does make path absolute if not.projectOutputPath(path)— for output filenames (likepage.html). Preserves the existingdirname + joinlogic since output names are relative to the source directory.Bisect
Last good: v1.9.17. First bad: v1.9.18 (77633b3).
Related
Follow up on preview fixes that introduced this
which was a regression of broader quarto preview behavior change
Also, in a way related to this observation we've done since new single project context is out