Skip to content

fix(utils): decode URL-encoded paths in stacktrace parser#9618

Open
22mb wants to merge 3 commits intovitest-dev:mainfrom
22mb:fix/spaces-in-path
Open

fix(utils): decode URL-encoded paths in stacktrace parser#9618
22mb wants to merge 3 commits intovitest-dev:mainfrom
22mb:fix/spaces-in-path

Conversation

@22mb
Copy link

@22mb 22mb commented Feb 9, 2026

Description

When running browser tests with vi.mock() in directories containing spaces, the mock resolution fails because browser stack traces contain URL-encoded paths (e.g., space%20dir/file.ts instead of space dir/file.ts).

This PR adds decodeURI to both V8 and Firefox/Safari stack trace parsers in packages/utils/src/source-map.ts.

Using decodeURI instead of decodeURIComponent to avoid decoding URI-special characters like /.

Resolves #7788, Resolves #9500

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link

netlify bot commented Feb 9, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 0b26abb
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/698d2397e7f3b90008557b84
😎 Deploy Preview https://deploy-preview-9618--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Browser stacktraces contain URL-encoded paths (e.g. %20 for whitespace).
Decode them using `decodeURI` API so mock resolution works for paths with whitespaces.

fix vitest-dev#7788, fix vitest-dev#9500
@22mb 22mb force-pushed the fix/spaces-in-path branch from d25c9b6 to 71d5330 Compare February 9, 2026 12:33
@hi-ogawa
Copy link
Contributor

Can you add test case for non browser tests for #9500?

@22mb
Copy link
Author

22mb commented Feb 10, 2026

Ok,I'll address it.

Add a core test case where `vi.mock()` caller is in a directory with spaces.
Also update test titles to reflect the actual issue.
@hi-ogawa hi-ogawa self-assigned this Feb 11, 2026
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the same test is passing on main already.

And now I'm trying to verify the reproduction of #9500. It fails on stackblitz but it passes when downloaded locally. It's possible that that was stackblitz thing.

That said, having this is fine, so we can keep it.

Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying decodeURI on non browser mode can cause breaking stacktrace e.g. repro-%20.test.ts becoming repro- .test.ts.

 FAIL  test/repro/repro-%20.test.ts > foo
AssertionError: expected +0 to be 1 // Object.is equality

- Expected
+ Received

- 1
+ 0

  test/repro/repro- .test.ts:7:13

Vite itself might not reliably support such file path on client, but Vitest should probably try to support where possible, so this decodeURI should happen only for browser mode. I'm not sure how we can detect that though.


Also, for the test case, if we are fixing parseStacktrace, it would be nice to have tests to check error stacktrace like above.

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.

Browser mode mocking doesn't work under directory with whitespaces Module mocks do not work when there are spaces in path

2 participants