grace/htmlua
HTML Templating Engine
git clone https://git.gae.moe/grace/htmlua
0213276
main
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 { 10const clean = try alloc . alloc ( u8 , path . len ) ; 11var list = ArrayList ( u8 ) . initBuffer ( clean ) ; 12var pit = std . mem . splitScalar ( u8 , path , '/' ) ; 13while ( pit . next ()) | part | { 14if ( part . len == 0 ) continue ; 15if ( std . mem . eql ( u8 , part , ".." )) continue ; 16// This should never actually allocate 17try list . appendSlice ( alloc , part ) ; 18try list . append ( alloc , '/' ) ; 19} 20const new_len = list . items . len - 1 ; 21_ = alloc . resize ( clean , new_len ) ; 22return clean [ 0 .. new_len ] ; 23}