fix: skip empty dependency names to prevent lockfile corruption#33243
Open
hijingsong wants to merge 1 commit intodenoland:mainfrom
Open
fix: skip empty dependency names to prevent lockfile corruption#33243hijingsong wants to merge 1 commit intodenoland:mainfrom
hijingsong wants to merge 1 commit intodenoland:mainfrom
Conversation
…rruption When package.json has an empty string dependency key (e.g., "": "."), the empty name propagates through to the lockfile as an invalid package requirement. On the first run, Deno serializes it to the lockfile, but on the second run, deserialization fails with "Invalid package requirement '@.'". Skip empty dependency names at both the parsing level (resolve_local_package_json_deps) and the lockfile collection level (collect_deps) so the invalid entry never reaches the lockfile. Fixes denoland#32113
|
|
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.
Problem
When
package.jsoncontains an empty-string dependency key (e.g.,"": "."), Deno works on the first run but corrupts the lockfile. On the second run, deserialization fails with:Fixes #32113
Root Cause
An empty dependency name passes through
PackageJsonDepValue::parse("", ".")and gets serialized into the lockfile as an invalid package requirement. When the lockfile is read back, the deserializer cannot parse it.Fix
Skip empty-string dependency names at two locations:
libs/package_json/lib.rs(resolve_local_package_json_deps): Filter out empty keys when building the dependency map. This prevents the invalid entry from entering the system at the parsing level.libs/resolver/lockfile.rs(collect_deps): Filter out empty keys when collecting link package deps for the lockfile. Belt-and-suspenders defense for the lockfile path specifically.Empty-string dependency names are not valid npm package identifiers and serve no purpose, so silently ignoring them is the correct behavior.
Testing
Manually verified with the reproduction case from #32113:
{ "dependencies": { "": "." } }Before: lockfile corruption on second run. After: empty entry is silently skipped.