From ad9225a4ca43b594941cc637a0aab53ae7d31954 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 9 Apr 2026 13:08:39 -0700 Subject: [PATCH] build: sanitize all invalid chars in branch name for version Fixes #11990 Previously only slashes were replaced with hyphens in the branch name used as the semver pre-release identifier. Branch names containing dots (e.g. dependabot branches like "cachix/install-nix-action-31.10.4") would cause an InvalidVersion error because std.SemanticVersion only allows alphanumeric characters and hyphens in pre-release identifiers. Replace all non-alphanumeric, non-hyphen characters instead of only slashes. --- src/build/GitVersion.zig | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/build/GitVersion.zig b/src/build/GitVersion.zig index 8b368d2cd..41cc7f84f 100644 --- a/src/build/GitVersion.zig +++ b/src/build/GitVersion.zig @@ -29,11 +29,14 @@ pub fn detect(b: *std.Build) !Version { error.ExitCodeFailure => return error.GitNotRepository, else => return err, }; - // Replace any '/' with '-' as including slashes will mess up building - // the dist tarball - the tarball uses the branch as part of the - // name and including slashes means that the tarball will end up in - // subdirectories instead of where it's supposed to be. - std.mem.replaceScalar(u8, tmp, '/', '-'); + + // Replace characters that are not valid in semantic version + // pre-release identifiers (which only allow [0-9A-Za-z-]). + // Slashes would also mess up dist tarball paths. + for (tmp) |*c| { + if (!std.ascii.isAlphanumeric(c.*) and c.* != '-') c.* = '-'; + } + break :b tmp; };