grace/htmlua

HTML Templating Engine

git clone https://git.gae.moe/grace/htmlua

Grace Yoderfeat: zig rewrite0213276

main
828 B23 linesraw
1const std = @import("std");
2const Io = std.Io;
3const File = Io.File;
4const Allocator = std.mem.Allocator;
5const ArenaAllocator = std.heap.ArenaAllocator;
6const ArrayList = std.ArrayList;
7const StringArrayHashMap = std.StringArrayHashMapUnmanaged;
8
9pub fn sanitizePath(alloc: Allocator, path: []const u8) ![]const u8 {
10    const clean = try alloc.alloc(u8, path.len);
11    var list = ArrayList(u8).initBuffer(clean);
12    var pit = std.mem.splitScalar(u8, path, '/');
13    while (pit.next()) |part| {
14        if (part.len == 0) continue;
15        if (std.mem.eql(u8, part, "..")) continue;
16        // This should never actually allocate
17        try list.appendSlice(alloc, part);
18        try list.append(alloc, '/');
19    }
20    const new_len = list.items.len - 1;
21    _ = alloc.resize(clean, new_len);
22    return clean[0..new_len];
23}