Skip to content

Commit 942d432

Browse files
authored
Fuzzer goodies (#104)
* html tokenizer: fix path that failed to report a tag name * fuzzer fixes * add duplicate id detection also implements correctly "namespacing" for `<template>` elements * support both zig 0.15 and 0.16.0-dev
1 parent 521458b commit 942d432

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+669
-564
lines changed

build.zig

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn build(b: *std.Build) !void {
2222
const superhtml = b.addModule("superhtml", .{
2323
.root_source_file = b.path("src/root.zig"),
2424
.target = target,
25+
.optimize = optimize,
2526
});
2627
superhtml.addImport("scripty", scripty.module("scripty"));
2728
superhtml.addImport("tracy", tracy.module("tracy"));
@@ -77,6 +78,22 @@ pub fn build(b: *std.Build) !void {
7778
if (version == .tag) {
7879
setupReleaseStep(b, options, superhtml, folders, lsp);
7980
}
81+
82+
setupGeneratorStep(b, target);
83+
}
84+
85+
fn setupGeneratorStep(b: *std.Build, target: std.Build.ResolvedTarget) void {
86+
const gen = b.step("generator", "Build generator executable for reproing fuzz cases");
87+
const supergen = b.addExecutable(.{
88+
.name = "generator",
89+
.root_module = b.createModule(.{
90+
.root_source_file = b.path("src/generator.zig"),
91+
.target = target,
92+
.optimize = .ReleaseSafe,
93+
}),
94+
});
95+
96+
gen.dependOn(&b.addInstallArtifact(supergen, .{}).step);
8097
}
8198

8299
fn setupCheckStep(
@@ -119,8 +136,7 @@ fn setupTestStep(
119136

120137
const unit_tests = b.addTest(.{
121138
.root_module = superhtml,
122-
// .strip = true,
123-
// .filter = "if-else-loop",
139+
.filters = b.args orelse &.{},
124140
});
125141

126142
const run_unit_tests = b.addRunArtifact(unit_tests);

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
.hash = "tracy-0.0.0-4Xw-1pwwAABTfMgoDP1unCbZDZhJEfict7XCBGF6IdIn",
1414
},
1515
.lsp_kit = .{
16-
.url = "git+https://github.com/kristoff-it/lsp-kit?ref=zig-0.15#01c14e592d25dc57dfebba27b8bd2b4aa91c1140",
17-
.hash = "lsp_kit-0.1.0-bi_PL5YyCgA2QFEza6llr2Uy08QUQsWBu2wKvtr8tbLx",
16+
.url = "git+https://github.com/zigtools/lsp-kit#fe98e895ca3bd1b39965ab30f0f252f7b7e83ee6",
17+
.hash = "lsp_kit-0.1.0-bi_PLzAyCgClDh8_M0U9Q50ysdsQBuRuBTZfwg6rZPd6",
1818
},
1919
.scripty = .{
2020
.url = "git+https://github.com/kristoff-it/scripty#50dbab8945440089384f26ec165d870c29555247",

src/cli.zig

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ pub fn panic(
3131
) noreturn {
3232
if (lsp_mode) {
3333
std.log.err("\n{s}\n\n{?f}", .{ msg, trace });
34-
} else {
35-
std.debug.print("\n{s}\n\n{?f}", .{ msg, trace });
3634
}
35+
3736
blk: {
3837
const out: std.fs.File = if (!lsp_mode) std.fs.File.stderr() else logging.log_file orelse break :blk;
3938
var writer = out.writerStreaming(&.{});
@@ -43,17 +42,13 @@ pub fn panic(
4342
w.print("Unable to dump stack trace: debug info stripped\n", .{}) catch {};
4443
break :blk;
4544
}
46-
const debug_info = std.debug.getSelfDebugInfo() catch |err| {
47-
w.print(
48-
"Unable to dump stack trace: Unable to open debug info: {s}\n",
49-
.{@errorName(err)},
50-
) catch {};
51-
break :blk;
52-
};
53-
std.debug.writeCurrentStackTrace(w, debug_info, .no_color, ret_addr) catch |err| {
54-
w.print("Unable to dump stack trace: {t}\n", .{err}) catch {};
55-
break :blk;
56-
};
45+
46+
if (builtin.zig_version.minor != 15) {
47+
std.debug.writeCurrentStackTrace(.{ .first_address = ret_addr }, w, .no_color) catch |err| {
48+
w.print("Unable to dump stack trace: {t}\n", .{err}) catch {};
49+
break :blk;
50+
};
51+
}
5752
}
5853

5954
if (builtin.mode == .Debug) @breakpoint();

src/cli/check.zig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
const builtin = @import("builtin");
12
const std = @import("std");
23
const super = @import("superhtml");
34

45
const FileType = enum { html, super };
56

6-
pub fn run(gpa: std.mem.Allocator, args: []const []const u8) !void {
7+
pub fn run(gpa: std.mem.Allocator, args: []const []const u8) !noreturn {
78
const cmd = Command.parse(args);
89
var any_error = false;
910
switch (cmd.mode) {
@@ -64,6 +65,7 @@ pub fn run(gpa: std.mem.Allocator, args: []const []const u8) !void {
6465
if (any_error) {
6566
std.process.exit(1);
6667
}
68+
std.process.exit(0);
6769
}
6870

6971
fn checkDir(
@@ -106,13 +108,19 @@ fn checkFile(
106108
defer _ = arena_impl.reset(.retain_capacity);
107109
const arena = arena_impl.allocator();
108110

109-
const in_bytes = try base_dir.readFileAllocOptions(
111+
const in_bytes = if (builtin.zig_version.minor == 15) try base_dir.readFileAllocOptions(
110112
arena,
111113
sub_path,
112114
super.max_size,
113115
null,
114116
.of(u8),
115117
0,
118+
) else try base_dir.readFileAllocOptions(
119+
sub_path,
120+
arena,
121+
.limited(super.max_size),
122+
.of(u8),
123+
0,
116124
);
117125

118126
const file_type: FileType = blk: {

0 commit comments

Comments
 (0)