Repository navigation
Conversation
`ParseWorkspaces` converted the decoded `workspaces` value with unchecked type
assertions, and the field is decoded into `any`, so whatever a scanned
repository's package.json contains reaches it:
"workspaces": {"packages": "packages/*"}
"workspaces": {"packages": {"a": "b"}}
"workspaces": ["packages/*", 1]
"workspaces": ["packages/*", {"a": "b"}]
Each of those panicked with an interface conversion error, from
`(*Parser).Parse`, so a single package.json was enough to fail the scan.
Both assertions are now checked. `packages` that is not an array yields no
workspaces, and an array keeps its string members and drops the rest, matching
how the rest of the file treats an unknown shape (the License field already
falls back to an empty list).
Test: one case per malformed shape, the documented shapes unchanged, and an end
to end Parse of the document from the issue.
lxcxjxhx
force-pushed
the
fix/nodejs-workspaces-malformed
branch
from
November 26, 2026 18:04
f13161f to
481b841
Compare
This branch has not been deployed
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.
Description
ParseWorkspacesconverted the decodedworkspacesfield with unchecked type assertions. The field is decoded intoany(types.go:16), so whatever a scanned repository'spackage.jsoncontains reaches the parser, and a malformed one panicked from(*Parser).Parse— one file was enough to fail the whole scan.Four shapes triggered it:
After
Both assertions are checked. A
packagesvalue that is not an array yields no workspaces, and an array keeps its string members and ignores the rest — the same treatment the file already gives an unknown shape:License.UnmarshalJSONfalls back to an empty list (types.go:70), and aworkspacesobject without apackageskey already returnednil.The documented shapes are unchanged:
"workspaces": ["packages/*", "backend"]and{"packages": ["packages/*", "plugins/*"]}produce exactly what they did before.Tests
workspaces_test.go:TestParseWorkspacesMalformed— the five malformed shapes above plus anilelement; each must not panic.TestParseWorkspacesValid— both documented shapes, an object withoutpackages, a bare string, andnil.TestParserWorkspacesNeverPanics— runsNewParser().Parseon thepackage.jsonfrom the issue and checks the package is still read.Red/green: with
parse.goreverted,TestParseWorkspacesMalformed/packages_is_a_stringfails withfunc (assert.PanicTestFunc) should not panic. With the fix,go test ./pkg/dependency/parser/nodejs/...passes for all five packages (bun, npm, packagejson, pnpm, yarn);gofmt -landgo vetare clean.Fixes #11765.