Skip to content

fix(utils): don't crash on a malformed inline source map (fix #10892) - #10893

Merged
hi-ogawa merged 11 commits into
vitest-dev:mainfrom
lazerg:fix/issue-10892-malformed-sourcemap
Aug 14, 2026
Merged

fix(utils): don't crash on a malformed inline source map (fix #10892)#10893
hi-ogawa merged 11 commits into
vitest-dev:mainfrom
lazerg:fix/issue-10892-malformed-sourcemap

Conversation

@lazerg

@lazerg lazerg commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Description

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:.

@lazerg

lazerg commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Both failing jobs look unrelated to this change. The Windows unit job fails the same way on main, in the typechecker OOM test. The macOS e2e job failed on a watch fixture that disappeared mid-run.

@hi-ogawa
hi-ogawa self-requested a review August 12, 2026 08:15

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should also try integration repro in vite and fix there too

// based on vite
// https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/server/sourcemap.ts#L149
export function extractSourcemapFromFile(

@hi-ogawa hi-ogawa self-assigned this Aug 12, 2026
Comment thread test/unit/test/utils.spec.ts
@lazerg

lazerg commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

I checked vite's own extractSourcemapFromFile (packages/vite/src/node/server/sourcemap.ts). Both call sites already wrap it in try/catch, and the module runner has a separate fix (#20554) for the same sourceMappingURL-in-a-string-literal case, so this crash doesn't happen there and no follow-up is needed on that side.

@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 072276c
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a7d239df2c8fd0008ae73e3
😎 Deploy Preview https://deploy-preview-10893--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

Comment on lines +71 to +76
// Split across a concat so this file's own transform doesn't treat it as
// its own (malformed) source map comment.
const malformedSourceMapComment = '//# source' + 'MappingURL=data:application/json;base64,bm90LWpzb24='

const { stderr, exitCode, buildTree } = await runInlineTests({
'malformed-source-map.js': `${malformedSourceMapComment}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can use real file fixture for better illustration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched to a real fixture file, thanks for the nudge.

lazerg and others added 6 commits August 12, 2026 13:45
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Comment on lines +192 to +193
// TODO: this uses client module graph and thus miss detects
// inlined modules in ssr environment as if external.

@hi-ogawa hi-ogawa Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Apparently test/e2e/fixtures/malformed-source-map/malformed-source-map.js case shouldn't have failed if we got this right. For now, just leaving inline TODO here and not creating its own issue since this misdetection doesn't have actually any consequence for mapping correctness (as we've covered extensively in other e2e).

@hi-ogawa
hi-ogawa merged commit fe79062 into vitest-dev:main Aug 14, 2026
26 of 28 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extractSourcemapFromFile crashes the run on a malformed source map, exiting non-zero with every test passing

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo