fix: escape interpolated paths in generated virtual modules#164
Merged
Conversation
Wrap every path spliced into the virtual:funstack/entries, client-init, and build-entry loaders with JSON.stringify, so paths containing quotes or other characters needing escaping in a JS string literal no longer produce syntax errors (or injected code) in the generated modules. Closes #149 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136xqmAz4YqZVWnTPZgZdik
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.
Summary
Fixes #149.
The
virtual:funstack/entries,client-init, andbuild-entryloaders inpackages/static/src/plugin/index.tsspliced resolved paths into generated code as raw string literals. A path containing a"(or other characters needing escaping in a JS string literal) would produce a syntax error — or in the worst case, injected code — in the generated module.All interpolated paths are now embedded with
JSON.stringify(...), matching how the fsRoutes glob pattern was already handled:RootandAppimportsRootandadapterimportsvirtual:funstack/client-init: the clientInit side-effect importvirtual:funstack/build-entry: the build entry re-exportTests
Added unit tests in
packages/static/src/plugin/index.test.tsthat runconfigResolvedwith a Vite root containing a"character and assert each generated virtual module embeds the correctly escaped path.pnpm test:run(107 tests),pnpm typecheck,pnpm lint, andpnpm format:checkall pass.🤖 Generated with Claude Code
https://claude.ai/code/session_0136xqmAz4YqZVWnTPZgZdik
Generated by Claude Code