From 0bccce8bf987d1fc84b355a67384c3dbb7807e0f Mon Sep 17 00:00:00 2001 From: Ankit Patial Date: Sun, 18 Jan 2026 00:04:44 +0530 Subject: [PATCH] Add configurable max_file_size option - Default 5 MB for template files - Configurable via ViewEngine.init options --- src/view_engine.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/view_engine.zig b/src/view_engine.zig index f040b15..284c996 100644 --- a/src/view_engine.zig +++ b/src/view_engine.zig @@ -45,6 +45,8 @@ pub const Options = struct { extension: []const u8 = ".pug", /// Enable pretty-printing with indentation. pretty: bool = true, + /// Maximum template file size in bytes. Defaults to 5 MB. + max_file_size: usize = 5 * 1024 * 1024, }; /// Error types for ViewEngine operations. @@ -88,7 +90,7 @@ pub const ViewEngine = struct { defer allocator.free(full_path); // Read template file - const source = std.fs.cwd().readFileAlloc(allocator, full_path, 1024 * 1024) catch { + const source = std.fs.cwd().readFileAlloc(allocator, full_path, self.options.max_file_size) catch { return ViewEngineError.TemplateNotFound; }; defer allocator.free(source); @@ -148,7 +150,7 @@ pub const ViewEngine = struct { return rt.renderOwned(doc); } - /// Resolves a template path relative to views directory. + /// Resolves a template path relative to views directory, adding extension if needed. fn resolvePath(self: *const ViewEngine, allocator: std.mem.Allocator, template_path: []const u8) ![]const u8 { // Add extension if not present const with_ext = if (std.mem.endsWith(u8, template_path, self.options.extension)) @@ -164,7 +166,7 @@ pub const ViewEngine = struct { fn createFileResolver() runtime.FileResolver { return struct { fn resolve(allocator: std.mem.Allocator, path: []const u8) ?[]const u8 { - return std.fs.cwd().readFileAlloc(allocator, path, 1024 * 1024) catch null; + return std.fs.cwd().readFileAlloc(allocator, path, 5 * 1024 * 1024) catch null; } }.resolve; }