Skip to content

Commit 41e9e7d

Browse files
committed
update to zig 0.16.0, relax checks on <iframe [allow]>
While superhtml is generally extremely rigid with what it accepts, in this case presenting users with errors relative to the allow attribute in an iframe element would be a source of issues that normal users would not be able to overcome. The syntax of [allow] is defined in a separate spec, presented with an ABNF grammar and popular tools (eg the embed feature on youtube) provide completely wrong code that an user would have an extremely hard time fixing. For this reason we're temporarily adding some leniency when parsing this attribute while we decide if there is a better way that doesn't imply presenting users with the ultimate html syntax puzzle.
1 parent 8b5bb27 commit 41e9e7d

File tree

24 files changed

+347
-262
lines changed

24 files changed

+347
-262
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.zig-cache/
22
zig-cache/
33
zig-out/
4+
zig-pkg/
45
release/
56
scratch
67

build.zig

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ pub fn build(b: *std.Build) !void {
55
const target = b.standardTargetOptions(.{});
66
const optimize = b.standardOptimizeOption(.{});
77
const enable_tracy = b.option(bool, "tracy", "Enable Tracy profiling") orelse false;
8-
const version = b.option([]const u8, "version", "Override the version of SuperHTML") orelse zon.version;
8+
const version = b.option(
9+
[]const u8,
10+
"version",
11+
"Override the version of SuperHTML",
12+
) orelse zon.version;
913

1014
const tracy = b.dependency("tracy", .{ .enable = enable_tracy });
1115
const scripty = b.dependency("scripty", .{
@@ -70,7 +74,7 @@ pub fn build(b: *std.Build) !void {
7074
setupWasmStep(b, optimize, options, superhtml, lsp);
7175
setupFetchLanguageSubtagRegistryStep(b, target);
7276

73-
const release = b.step("release", "Create release builds of Zine");
77+
const release = b.step("release", "Create release builds of SuperHTML");
7478
const git_version = getGitVersion(b);
7579
if (git_version == .tag) {
7680
if (std.mem.eql(u8, version, git_version.tag[1..])) {
@@ -200,7 +204,7 @@ fn setupWasmStep(
200204
superhtml: *std.Build.Module,
201205
lsp: *std.Build.Dependency,
202206
) void {
203-
const wasm = b.step("wasm", "Generate a WASM build of the SuperHTML LSP for VSCode");
207+
const wasm = b.step("wasm", "Generate a WASM build of the SuperHTML LSP");
204208
const super_wasm_lsp = b.addExecutable(.{
205209
.name = "superhtml",
206210
.root_module = b.createModule(.{
@@ -298,7 +302,7 @@ fn setupReleaseStep(
298302
});
299303
const archive = zip.addOutputFileArg(archive_name);
300304
zip.addDirectoryArg(super_exe_release.getEmittedBin());
301-
_ = zip.captureStdOut();
305+
_ = zip.captureStdOut(.{});
302306

303307
release_step.dependOn(&b.addInstallFileWithDir(
304308
archive,
@@ -321,7 +325,7 @@ fn setupReleaseStep(
321325

322326
tar.addDirectoryArg(super_exe_release.getEmittedBinDirectory());
323327
tar.addArg("superhtml");
324-
_ = tar.captureStdOut();
328+
_ = tar.captureStdOut(.{});
325329

326330
release_step.dependOn(&b.addInstallFileWithDir(
327331
archive,
@@ -352,7 +356,7 @@ fn setupReleaseStep(
352356
super_wasm_lsp.root_module.addImport("lsp", lsp.module("lsp"));
353357
super_wasm_lsp.root_module.addOptions("build_options", options);
354358

355-
const archive_name = "wasm-wasi-lsponly.tar.xz";
359+
const archive_name = "wasm32-wasi-lsponly.tar.xz";
356360
const tar = b.addSystemCommand(&.{
357361
"gtar",
358362
"-cJf",
@@ -361,7 +365,7 @@ fn setupReleaseStep(
361365
tar.addArg("-C");
362366
tar.addDirectoryArg(super_wasm_lsp.getEmittedBinDirectory());
363367
tar.addArg("superhtml.wasm");
364-
_ = tar.captureStdOut();
368+
_ = tar.captureStdOut(.{});
365369
release_step.dependOn(&b.addInstallFileWithDir(
366370
archive,
367371
.{ .custom = "releases" },
@@ -395,7 +399,7 @@ fn getGitVersion(b: *std.Build) Version {
395399
b.build_root.path.?, "describe",
396400
"--match", "*.*.*",
397401
"--tags",
398-
}, &out, .Ignore) catch return .unknown,
402+
}, &out, .ignore) catch return .unknown,
399403
" \n\r",
400404
);
401405

build.zig.zon

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
.minimum_zig_version = "0.15.1",
66
.dependencies = .{
77
.known_folders = .{
8-
.url = "git+https://github.com/ziglibs/known-folders#ab5cf5feb936fa3b72c95d3ad0c0c67791937ba1",
9-
.hash = "known_folders-0.0.0-Fy-PJtTTAADUOhGKM0sxzG4eMkNQxRvx9e5dfHVyaeA3",
8+
.url = "git+https://github.com/ziglibs/known-folders#175f5596b3d2ee3c658282bb07885580895a0e73",
9+
.hash = "known_folders-0.0.0-Fy-PJk7KAAC41mQXzmFyGa0Q7tvmQjatENkREa6Gc4zu",
1010
},
1111
.tracy = .{
1212
.url = "git+https://github.com/kristoff-it/tracy#67d2d89e351048c76fc6d161e0ac09d8a831dc60",
1313
.hash = "tracy-0.0.0-4Xw-1pwwAABTfMgoDP1unCbZDZhJEfict7XCBGF6IdIn",
1414
},
1515
.lsp_kit = .{
16-
.url = "git+https://github.com/zigtools/lsp-kit#fe98e895ca3bd1b39965ab30f0f252f7b7e83ee6",
17-
.hash = "lsp_kit-0.1.0-bi_PLzAyCgClDh8_M0U9Q50ysdsQBuRuBTZfwg6rZPd6",
16+
.url = "git+https://github.com/zigtools/lsp-kit#ec325a3c33d1da7708cf513355208f74d9560580",
17+
.hash = "lsp_kit-0.1.0-bi_PL_kyDACVTEhLaMq2-PJx0MocqRyjXDAN0ybMUyQQ",
1818
},
1919
.scripty = .{
20-
.url = "git+https://github.com/kristoff-it/scripty#50dbab8945440089384f26ec165d870c29555247",
21-
.hash = "scripty-0.1.0-LKK5O7v4AADWWXuFcTJky_5sY12tmw3kRi3k2wkpfxAX",
20+
.url = "git+https://github.com/kristoff-it/scripty#154779b47be67f766ee13080ce7aa68a18daebd9",
21+
.hash = "scripty-0.1.0-LKK5OwTdAACftzrZyMpWZUJ7OLyI3UwAwqQfE2cdgRoO",
2222
},
2323
},
2424
.paths = .{

editors/vscode/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change Log
22

3-
All notable changes to the "super" extension will be documented in this file.
3+
All notable changes to the SuperHTML extension will be documented in this file.
44

55
## [v0.6.2]
66
- The "boolean attributes cannot have a value" error now puts squigglies under the attribute name instead of the value.

editors/vscode/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
// createStdioOptions,
3+
createUriConverters,
34
startServer
45
} from '@vscode/wasm-wasi-lsp';
56
import { ProcessOptions, Stdio, Wasm } from '@vscode/wasm-wasi/v1';
@@ -69,7 +70,7 @@ export async function activate(context: ExtensionContext) {
6970
const serverOptions: ServerOptions = async () => {
7071
const options: ProcessOptions = {
7172
stdio: createStdioOptions(),
72-
// mountPoints: [{ kind: 'workspaceFolder' }]
73+
// mountPoints: [{ kind: 'workspaceFolder' }],
7374
args: args,
7475
};
7576

@@ -105,6 +106,7 @@ export async function activate(context: ExtensionContext) {
105106
{ scheme: "file", language: 'superhtml' },
106107
],
107108
outputChannel: channel,
109+
uriConverters: createUriConverters()
108110
};
109111

110112
client = new LanguageClient(

src/Ast.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Ast = @This();
22

33
const std = @import("std");
4+
const Io = std.Io;
45
const Allocator = std.mem.Allocator;
56
const Writer = std.Io.Writer;
67
const builtin = @import("builtin");
@@ -148,12 +149,13 @@ pub const Node = struct {
148149

149150
pub fn debug(
150151
node: *const Node,
152+
io: Io,
151153
src: []const u8,
152154
html_ast: html.Ast,
153155
ast: Ast,
154156
) void {
155157
std.debug.print("\n\n-- DEBUG --\n", .{});
156-
var stderr = std.fs.File.stderr().writer(&.{});
158+
var stderr = Io.File.stderr().writer(io, &.{});
157159
node.debugInternal(
158160
src,
159161
html_ast,
@@ -408,8 +410,8 @@ pub fn root(ast: Ast) Node {
408410
const Parser = struct {
409411
src: []const u8,
410412
html: html.Ast,
411-
nodes: std.ArrayListUnmanaged(Node) = .{},
412-
errors: std.ArrayListUnmanaged(Error) = .{},
413+
nodes: std.ArrayList(Node) = .empty,
414+
errors: std.ArrayList(Error) = .empty,
413415
extends_idx: u32 = 0,
414416
interface: std.StringArrayHashMapUnmanaged(u32) = .{},
415417
blocks: std.StringHashMapUnmanaged(u32) = .{},
@@ -1119,7 +1121,7 @@ test "basics" {
11191121
const r = tree.root();
11201122
try std.testing.expectEqual(Node.Kind.root, r.kind);
11211123

1122-
errdefer r.debug(case, html_ast, tree);
1124+
errdefer r.debug(std.testing.io, case, html_ast, tree);
11231125

11241126
try std.testing.expectEqual(0, r.parent_idx);
11251127
try std.testing.expectEqual(0, r.next_idx);

src/cli/check.zig

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
const builtin = @import("builtin");
22
const std = @import("std");
3+
const Io = std.Io;
4+
const Allocator = std.mem.Allocator;
35
const super = @import("superhtml");
46

57
const FileType = enum { html, super };
68

7-
pub fn run(gpa: std.mem.Allocator, args: []const []const u8) !noreturn {
9+
pub fn run(io: Io, gpa: Allocator, args: []const []const u8) !noreturn {
810
const cmd = Command.parse(args);
911
var any_error = false;
1012
switch (cmd.mode) {
1113
.stdin => {
12-
var fr = std.fs.File.stdin().reader(&.{});
14+
var fr = std.Io.File.stdin().reader(io, &.{});
1315
var aw: std.Io.Writer.Allocating = .init(gpa);
1416
_ = try fr.interface.streamRemaining(&aw.writer);
1517
const in_bytes = try aw.toOwnedSliceSentinel(0);
1618

17-
try checkHtml(gpa, null, in_bytes, cmd.syntax_only);
19+
try checkHtml(io, gpa, null, in_bytes, cmd.syntax_only);
1820
},
1921
.stdin_super => {
20-
var fr = std.fs.File.stdin().reader(&.{});
22+
var fr = std.Io.File.stdin().reader(io, &.{});
2123
var aw: std.Io.Writer.Allocating = .init(gpa);
2224
_ = try fr.interface.streamRemaining(&aw.writer);
2325
const in_bytes = try aw.toOwnedSliceSentinel(0);
2426

25-
try checkSuper(gpa, null, in_bytes, cmd.syntax_only);
27+
try checkSuper(io, gpa, null, in_bytes, cmd.syntax_only);
2628
},
2729
.paths => |paths| {
2830
// checkFile will reset the arena at the end of each call
2931
var arena_impl = std.heap.ArenaAllocator.init(gpa);
3032
for (paths) |path| {
3133
checkFile(
34+
io,
3235
&arena_impl,
33-
std.fs.cwd(),
36+
Io.Dir.cwd(),
3437
path,
3538
path,
3639
&any_error,
3740
cmd.syntax_only,
3841
) catch |err| switch (err) {
3942
error.IsDir, error.AccessDenied => {
4043
checkDir(
44+
io,
4145
gpa,
4246
&arena_impl,
4347
path,
@@ -69,20 +73,22 @@ pub fn run(gpa: std.mem.Allocator, args: []const []const u8) !noreturn {
6973
}
7074

7175
fn checkDir(
76+
io: Io,
7277
gpa: std.mem.Allocator,
7378
arena_impl: *std.heap.ArenaAllocator,
7479
path: []const u8,
7580
any_error: *bool,
7681
syntax_only: bool,
7782
) !void {
78-
var dir = try std.fs.cwd().openDir(path, .{ .iterate = true });
79-
defer dir.close();
83+
var dir = try Io.Dir.cwd().openDir(io, path, .{ .iterate = true });
84+
defer dir.close(io);
8085
var walker = dir.walk(gpa) catch oom();
8186
defer walker.deinit();
82-
while (try walker.next()) |item| {
87+
while (try walker.next(io)) |item| {
8388
switch (item.kind) {
8489
.file => {
8590
try checkFile(
91+
io,
8692
arena_impl,
8793
item.dir,
8894
item.basename,
@@ -97,8 +103,9 @@ fn checkDir(
97103
}
98104

99105
fn checkFile(
106+
io: Io,
100107
arena_impl: *std.heap.ArenaAllocator,
101-
base_dir: std.fs.Dir,
108+
base_dir: Io.Dir,
102109
sub_path: []const u8,
103110
full_path: []const u8,
104111
any_error: *bool,
@@ -108,14 +115,8 @@ fn checkFile(
108115
defer _ = arena_impl.reset(.retain_capacity);
109116
const arena = arena_impl.allocator();
110117

111-
const in_bytes = if (builtin.zig_version.minor == 15) try base_dir.readFileAllocOptions(
112-
arena,
113-
sub_path,
114-
super.max_size,
115-
null,
116-
.of(u8),
117-
0,
118-
) else try base_dir.readFileAllocOptions(
118+
const in_bytes = try base_dir.readFileAllocOptions(
119+
io,
119120
sub_path,
120121
arena,
121122
.limited(super.max_size),
@@ -139,12 +140,14 @@ fn checkFile(
139140

140141
switch (file_type) {
141142
.html => try checkHtml(
143+
io,
142144
arena,
143145
full_path,
144146
in_bytes,
145147
syntax_only,
146148
),
147149
.super => try checkSuper(
150+
io,
148151
arena,
149152
full_path,
150153
in_bytes,
@@ -154,35 +157,37 @@ fn checkFile(
154157
}
155158

156159
pub fn checkHtml(
160+
io: Io,
157161
arena: std.mem.Allocator,
158162
path: ?[]const u8,
159163
code: [:0]const u8,
160164
syntax_only: bool,
161165
) !void {
162166
const ast = try super.html.Ast.init(arena, code, .html, syntax_only);
163167
if (ast.errors.len > 0) {
164-
var stderr = std.fs.File.stderr().writer(&.{});
168+
var stderr = Io.File.stderr().writer(io, &.{});
165169
try ast.printErrors(code, path, &stderr.interface);
166170
std.process.exit(1);
167171
}
168172
}
169173

170174
fn checkSuper(
175+
io: Io,
171176
arena: std.mem.Allocator,
172177
path: ?[]const u8,
173178
code: [:0]const u8,
174179
syntax_only: bool,
175180
) !void {
176181
const html = try super.html.Ast.init(arena, code, .superhtml, syntax_only);
177182
if (html.errors.len > 0) {
178-
var stderr = std.fs.File.stderr().writer(&.{});
183+
var stderr = Io.File.stderr().writer(io, &.{});
179184
try html.printErrors(code, path, &stderr.interface);
180185
std.process.exit(1);
181186
}
182187

183188
const s = try super.Ast.init(arena, html, code);
184189
if (s.errors.len > 0) {
185-
var stderr = std.fs.File.stderr().writer(&.{});
190+
var stderr = Io.File.stderr().writer(io, &.{});
186191
try s.printErrors(code, path, &stderr.interface);
187192
std.process.exit(1);
188193
}

0 commit comments

Comments
 (0)