fix(versions): handle invalid semver strings in the version list sort - #154
Conversation
semver.rcompare throws when either argument is not a valid semver string. A registered version with nonstandard probe output (pre-release builds, modded launchers, or parse failures) crashed the entire versions page. Check semver.valid() before comparing. Valid versions sort among themselves with rcompare as before. Invalid ones sort last, ordered alphabetically so the list stays deterministic. Fixes #148
Pixnop
left a comment
There was a problem hiding this comment.
The comparator is correct and I checked the property that usually goes wrong in hand-written ones: the signs are symmetric (valid beats invalid from both sides), valids keep the exact old ordering among themselves, and invalids get a deterministic alphabetical tail, so the sort cannot flicker between renders. One thing before approve, and it is a single test. This fixes a white-screen crash, and nothing in the diff fails without the fix: the renderer-dom harness already has versionsListVersions.test.tsx, so seeding one version entry with a nonstandard string (the '1.20' or 'Vintage Story 1.21.0' shapes from issue #148) and asserting the page renders both rows is cheap, fails against dev with the semver throw, and pins the guard. The repo has held every behavior change to that bar for two days, including mine, and a crash fix is the last place to make an exception.
Seed a version entry with a non-parseable string ("Vintage Story 1.21.0")
and assert both rows render. This test fails against dev, where
semver.rcompare throws on the invalid string and crashes the page.
|
Added in fc99ca5. The test seeds a version entry with |
Pixnop
left a comment
There was a problem hiding this comment.
Approving. Verified the new test bites: on the branch the file passes 4 for 4, and with only ListVersions.tsx reverted to dev the new case fails on exactly the advertised TypeError, so the white-screen guard is genuinely pinned. Comparator verdict from the first round stands: symmetric signs, old ordering preserved among valids, deterministic tail for invalids.
semver.rcomparethrows when either argument is not a valid semver string. A registered version with nonstandard-vprobe output (pre-release builds, modded launchers, or parse failures) crashed the entire versions page.What changed
src/renderer/src/features/versions/pages/ListVersions.tsx: replace the baresemver.rcompare()sort with a safe comparator that checkssemver.valid()first. Valid versions sort among themselves withrcompareas before. Invalid ones sort last, ordered alphabetically so the list stays deterministic.What was tested
npm run typecheckpassesnpm run lint:cipassesnpm run test:coveragepasses (1110 tests)Fixes #148