fix: normalize uppercase version prefix and harden version resolve lookup#62
Merged
Conversation
…okup sanitize() now strips a leading v/V case-insensitively so inputs like "V1.2.3" resolve to a valid release tag instead of "vV1.2.3". resolve() now uses Object.hasOwn for the mappings lookup so a version string matching an inherited Object.prototype key (e.g. "toString", "constructor") is passed through unchanged instead of returning an inherited value. https://claude.ai/code/session_01SiiCitU5rTuvXvNGmMLzmP
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.
Summary
Fixes two correctness issues in
src/versions.tssurfaced by a/huntscan ofsrc/:sanitize()— case-sensitivevstrip:version.replace(/^v/, '')only removed a lowercasev, so an input likeV1.2.3becamevV1.2.3, producing an invalid release tag and a 404 download URL. Now uses/^v/isoV1.2.3→v1.2.3. Empty/whitespace/latestbehavior is unchanged.resolve()— prototype-chain lookup:mappings[version] || versionread throughObject.prototype, so a version string equal to an inherited key (toString,constructor,hasOwnProperty) returned an inherited value instead of the input. Now usesObject.hasOwn(mappings, version)so such inputs pass through unchanged. Currently latent (sanitize prefixesv), fixed defensively.dist/bundle rebuilt (npm run package) to stay in sync withsrc/.Test plan
__tests__/versions.test.ts: uppercaseVprefix normalization (V1.2.3,V0.9.0) and prototype-key passthrough (toString,constructor,hasOwnProperty)npm test— 41/41 passed, 3/3 suites, 100% coverage onversions.tsnpm run lint(eslint) — cleannpm run format:check(prettier) — cleandist/index.jscontains the fixed codehttps://claude.ai/code/session_01SiiCitU5rTuvXvNGmMLzmP
Generated by Claude Code