Package.Manifest: enforce name limit of 32

This commit is contained in:
Andrew Kelley
2025-02-24 17:36:23 -08:00
parent a57b0a0f2f
commit 76e8b297b1

View File

@@ -9,6 +9,7 @@ const Package = @import("../Package.zig");
pub const max_bytes = 10 * 1024 * 1024;
pub const basename = "build.zig.zon";
pub const max_name_len = 32;
pub const Dependency = struct {
location: Location,
@@ -365,6 +366,11 @@ const Parse = struct {
if (!std.zig.isValidId(name))
return fail(p, main_token, "name must be a valid bare zig identifier (hint: switch from string to enum literal)", .{});
if (name.len > max_name_len)
return fail(p, main_token, "name '{s}' exceeds max length of {d}", .{
std.zig.fmtId(name), max_name_len,
});
return name;
}
@@ -375,6 +381,11 @@ const Parse = struct {
if (mem.startsWith(u8, ident_name, "@"))
return fail(p, main_token, "name must be a valid bare zig identifier", .{});
if (ident_name.len > max_name_len)
return fail(p, main_token, "name '{s}' exceeds max length of {d}", .{
std.zig.fmtId(ident_name), max_name_len,
});
return ident_name;
}