| ... | @@ -4787,7 +4787,7 @@ fn sanitizeExampleName(arena: Allocator, bytes: []const u8) error{OutOfMemory}![ | ... | @@ -4787,7 +4787,7 @@ fn sanitizeExampleName(arena: Allocator, bytes: []const u8) error{OutOfMemory}![ |
| 4787 | '-', '.', ' ' => try result.append(arena, '_'), | 4787 | '-', '.', ' ' => try result.append(arena, '_'), |
| 4788 | else => continue, | 4788 | else => continue, |
| 4789 | }; | 4789 | }; |
| 4790 | if (result.items.len == 0) return "foo"; | 4790 | if (!std.zig.isValidId(result.items)) return "foo"; |
| 4791 | if (result.items.len > Package.Manifest.max_name_len) | 4791 | if (result.items.len > Package.Manifest.max_name_len) |
| 4792 | result.shrinkRetainingCapacity(Package.Manifest.max_name_len); | 4792 | result.shrinkRetainingCapacity(Package.Manifest.max_name_len); |
| 4793 | | 4793 | |
| ... | @@ -4805,6 +4805,10 @@ test sanitizeExampleName { | ... | @@ -4805,6 +4805,10 @@ test sanitizeExampleName { |
| 4805 | try std.testing.expectEqualStrings("a", try sanitizeExampleName(arena, "!a")); | 4805 | try std.testing.expectEqualStrings("a", try sanitizeExampleName(arena, "!a")); |
| 4806 | try std.testing.expectEqualStrings("a_b", try sanitizeExampleName(arena, "a.b!")); | 4806 | try std.testing.expectEqualStrings("a_b", try sanitizeExampleName(arena, "a.b!")); |
| 4807 | try std.testing.expectEqualStrings("_01234", try sanitizeExampleName(arena, "01234")); | 4807 | try std.testing.expectEqualStrings("_01234", try sanitizeExampleName(arena, "01234")); |
| | 4808 | try std.testing.expectEqualStrings("foo", try sanitizeExampleName(arena, "error")); |
| | 4809 | try std.testing.expectEqualStrings("foo", try sanitizeExampleName(arena, "test")); |
| | 4810 | try std.testing.expectEqualStrings("tests", try sanitizeExampleName(arena, "tests")); |
| | 4811 | try std.testing.expectEqualStrings("test_project", try sanitizeExampleName(arena, "test project")); |
| 4808 | } | 4812 | } |
| 4809 | | 4813 | |
| 4810 | fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | 4814 | fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |