fix: resolve the input path against the root before making it virtual - #1
Closed
msallin wants to merge 1 commit into
Closed
fix: resolve the input path against the root before making it virtual#1msallin wants to merge 1 commit into
msallin wants to merge 1 commit into
Conversation
A Typst virtual path only accepts forward slashes, and `VirtualPath::new` was handed the caller's path verbatim. On Windows an ordinary relative path such as `templates\letter.typ` therefore failed to convert, and the `unwrap` turned that into a panic inside `create_compiler`. That function is `extern "C"` and has no unwind guard, so the panic aborted the whole host process rather than failing the single call. Relative paths are now joined onto the project root and converted with `VirtualPath::virtualize`, which splits on the platform separator and does the root containment check itself. A path that genuinely escapes the root reports an error through the existing channel instead of panicking, and the manual UTF-8 check is no longer needed because `virtualize` covers it.
msallin
force-pushed
the
fix/input-path-virtualize
branch
from
September 4, 2026 11:19
fbe3674 to
c66c2df
Compare
Member
Author
|
Superseded by evolvedlight#37; the fix belongs upstream. |
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.
Problem
A Typst virtual path only accepts forward slashes.
SystemWorld::newhanded the caller's input path toVirtualPath::newverbatim and unwrapped the result, so on Windows an ordinary relative path such astemplates\letter.typfailed to convert and panicked.The panic happens inside
create_compiler, which isextern "C"and has no unwind guard. A panic cannot unwind out of anextern "C"frame, so the process aborts rather than the call failing. Running the new tests againstdevelop:For a service on Windows, or any layout that sets an explicit root and keeps templates in a subfolder, this terminates the host process on the first compile with no managed exception. A
..component in the path does the same.Change
Relative paths are joined onto the project root, then converted with
VirtualPath::virtualize, which splits on the platform separator and performs the root containment check itself. A path that escapes the root now returns an error through the existing channel instead of panicking.The manual
to_strUTF-8 check is dropped becausevirtualizereports that case asVirtualizeError::Utf8. The<main>unwrap becomes anexpectnaming the invariant.This does not add an unwind guard to
create_compiler; that is a separate concern and other panic sources remain.Tests
New
src/typst_core/tests/input_path.rscovers a nested relative path, the equivalent absolute path, a relative path escaping the root, and an absolute path outside the root. New tests inTests.cscover the same cases through the managed API.All four Rust tests abort the test binary against
developand pass with the change.