Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/install/pnpm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ pub fn migratePnpmLockfile(
return error.PnpmLockfileMissingVersion;
};

const lockfile_version_num: u32 = lockfile_version: {
const lockfile_version_num: f64 = lockfile_version: {
err: {
switch (lockfile_version_expr.data) {
.e_number => |num| {
if (num.value < 0 or num.value > std.math.maxInt(u32)) {
if (num.value < 0) {
break :err;
}

break :lockfile_version @intFromFloat(std.math.divExact(f64, num.value, 1) catch break :err);
break :lockfile_version num.value;
},
.e_string => |version_str| {
const str = version_str.slice(allocator);

const end = strings.indexOfChar(str, '.') orelse str.len;
break :lockfile_version std.fmt.parseUnsigned(u32, str[0..end], 10) catch break :err;
break :lockfile_version std.fmt.parseFloat(f64, str[0..end]) catch break :err;
Comment on lines 121 to +122

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify: Parsing only major version, not full decimal version.

The code finds the first dot and parses only up to that point: str[0..end] where end = indexOfChar(str, '.') orelse str.len.

For a version string like "5.4":

  • end would be 1 (index of the first dot)
  • str[0..end] would be "5"
  • Result: only the major version 5.0 is parsed, not 5.4

This contradicts the PR description stating that versions like 5.4 should be handled. If the intent is to parse the full version including the decimal component, the code should parse the entire string, not just up to the first dot.

If this is intentional (only major version matters for the version check at line 132), please clarify. Otherwise, apply this diff:

                .e_string => |version_str| {
                    const str = version_str.slice(allocator);
-
-                    const end = strings.indexOfChar(str, '.') orelse str.len;
-                    break :lockfile_version std.fmt.parseFloat(f64, str[0..end]) catch break :err;
+                    break :lockfile_version std.fmt.parseFloat(f64, str) catch break :err;
                },

Run this script to check if the test fixture uses a version with a decimal component:


🏁 Script executed:

#!/bin/bash
# Check the pnpm-lock.yaml fixture for lockfileVersion value
fd -t f "pnpm-lock.yaml" test/cli/install/migration/pnpm/version-number-dot --exec cat {} \; | head -20

Length of output: 20


Parse full version string for lockfileVersion
The code slices at the first dot and only parses the major version, but the fixture uses lockfileVersion: 5.4, so this yields 5.0 instead of 5.4. Replace lines 121–122 with:

-    const end = strings.indexOfChar(str, '.') orelse str.len;
-    break :lockfile_version std.fmt.parseFloat(f64, str[0..end]) catch break :err;
+    break :lockfile_version std.fmt.parseFloat(f64, str) catch break :err;

This ensures decimal versions like 5.4 are parsed correctly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const end = strings.indexOfChar(str, '.') orelse str.len;
break :lockfile_version std.fmt.parseUnsigned(u32, str[0..end], 10) catch break :err;
break :lockfile_version std.fmt.parseFloat(f64, str[0..end]) catch break :err;
break :lockfile_version std.fmt.parseFloat(f64, str) catch break :err;
🤖 Prompt for AI Agents
In src/install/pnpm.zig around lines 121 to 122, the code slices the version
string at the first dot and thus only parses the major version (yielding 5
instead of 5.4); replace the slice+parse with calling std.fmt.parseFloat on the
full str (i.e., remove the 0..end slice and pass str directly) and keep the same
error handling so decimal lockfileVersion values like "5.4" are parsed
correctly.

},
else => {},
}
Expand Down
19 changes: 19 additions & 0 deletions test/cli/install/migration/pnpm-migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ test("basic", async () => {
expect(err).not.toContain("Saved lockfile");
});

test("version is number with dot", async () => {
const { packageDir, packageJson } = await verdaccio.createTestDir({
files: join(import.meta.dir, "pnpm/version-number-dot"),
});

let proc = spawn({
cmd: [bunExe(), "install"],
cwd: packageDir,
env,
stdout: "pipe",
stderr: "pipe",
});

let [out, err, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);

expect(exitCode).toBe(1);
expect(err).toContain("pnpm-lock.yaml version is too old (< v7)");
});

describe.todo("bin", () => {
test("manifests are fetched for bins", async () => {
const { packageDir, packageJson } = await verdaccio.createTestDir({
Expand Down
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.