Skip to content

fix: unescape webpack/rspack resource paths in load and transform - #627

Closed
antfu wants to merge 2 commits into
mainfrom
fix/unescape-resource-path
Closed

antfu wants to merge 2 commits into
mainfrom
fix/unescape-resource-path

Conversation

@antfu

@antfu antfu commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #591. Replaces #592.

Webpack escapes special characters in a resource path with a \0 prefix (msg#hash.js becomes msg\0#hash.js), and rspack does the same with a zero-width space (\u200B). load and transform received these escaped paths.

  • Add unescapeResourcePath(path, framework) and use it in the webpack and rspack load and transform loaders
  • Use each bundler's own escape character and unescape any escaped character, not only #
  • In load, unescape real paths only. Virtual module ids are decoded as before, because ids such as \0virtual:foo (Rollup convention) must keep their leading \0
  • Test with real webpack and rspack builds of a msg#hash.js file and a \0-prefixed virtual id, plus unit tests for the helper

Builds on #592 by @edemaine and keeps its approach; rebased on current main with a smaller test instead of a fixture per bundler.

Not changed: for virtual modules, transform still receives the encoded virtual path (_virtual_%00...) rather than the decoded id that load gets.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of file paths containing escaped characters in webpack and Rspack. These paths now reach loading and transformation steps consistently, including when source maps are merged.
    • Virtual module identifiers retain their existing decoding behavior.
  • Tests

    • Added coverage for escaped file paths and virtual modules across both bundlers, including checks that each bundler’s path escapes are handled independently.

Co-authored-by: edemaine <edemaine@mit.edu>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: addf2044-1be5-4190-843c-b2d461d4da7c
Commits

Reviewing files that changed from the base of the PR and between 3b0c45e and 703f7de.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f548464-779e-44b7-bdc4-64416d10a144
Commits

Reviewing files that changed from the base of the PR and between 8c654d1 and 3b0c45e.

Files selected for processing: 6
  • src/rspack/loaders/load.ts
  • src/rspack/loaders/transform.ts
  • src/utils/webpack-like.ts
  • src/webpack/loaders/load.ts
  • src/webpack/loaders/transform.ts
  • test/unit-tests/escaped-path/escaped-path.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Walkthrough

Webpack and Rspack now unescape real resource paths before passing IDs to load and transform processing. Virtual module ID handling remains unchanged. New tests cover hash-containing paths and both bundlers’ escape characters.

Changes: Escaped resource path normalization

Layer / File(s) Summary
Shared unescaping and load hooks
src/utils/webpack-like.ts, src/webpack/loaders/load.ts, src/rspack/loaders/load.ts
Adds bundler-specific resource path unescaping and applies it to non-virtual IDs passed to the load hooks. Virtual IDs retain their existing decoding behavior.
Transform IDs and integration tests
src/webpack/loaders/transform.ts, src/rspack/loaders/transform.ts, test/unit-tests/escaped-path/escaped-path.test.ts
Uses normalized IDs for transform filters, handlers, and source-map merging. Tests check hash-containing paths, virtual IDs, and the utility’s bundler-specific behavior.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • unjs/unplugin#608: Wires the Rspack loaders into the Rsbuild integration, which uses the loaders changed here.
  • unjs/unplugin#626: Changes the same webpack and Rspack transform loaders and their source-map handling.

Suggested reviewers: sxzz, boluwatifeajayi

Merge Risk: Minimal · previous review 3b0c4

The change unescapes webpack and rspack resource paths before they reach load and transform hooks, so paths containing characters like # can be read correctly. No concrete defect was identified in the reviewed changes, and the added tests cover both bundlers and the escape helper. Merge risk is minimal.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: unescaping webpack and Rspack resource paths in the load and transform loaders.
Linked Issues check Passed Issue #591 requires usable, unescaped paths in webpack and rspack load and transform hooks. The loaders call unescapeResourcePath with the correct bundler. load preserves virtual module decodi…
Out of Scope Changes check Passed The changes stay within issue #591. The helper, four loader updates, and unit/build tests directly implement or verify escaped resource-path handling. No unrelated behavior or files are changed.
Full details: Linked Issues check

Explanation

Issue #591 requires usable, unescaped paths in webpack and rspack load and transform hooks. The loaders call unescapeResourcePath with the correct bundler. load preserves virtual module decoding and leading \0 IDs. transform uses the unescaped ID for filtering, the hook argument, and source-map merging. The new tests run webpack and rspack builds with msg#hash.js, verify both hooks receive the real path, verify the virtual \0 ID, and test both escape characters.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/unjs/unplugin@627

commit: 703f7de

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webpack/rspack call load and transform with escaped paths

1 participant