@@ -90,11 +90,11 @@ pub const InputSanitizer = struct {
9090 continue ;
9191 };
9292
93- try normalized .appendSlice (utf8_bytes [0.. written ]);
93+ try normalized .appendSlice (self . allocator , utf8_bytes [0.. written ]);
9494 i += utf8_len ;
9595 }
9696
97- return normalized .toOwnedSlice ();
97+ return normalized .toOwnedSlice (self . allocator );
9898 }
9999
100100 /// Apply normalization rules to individual codepoints
@@ -475,7 +475,7 @@ pub const InputSanitizer = struct {
475475 if (input .len == 0 ) return .BLOCKED ;
476476
477477 // Check for valid command format: command [subcommand] [args...]
478- var parts = std .mem .split (u8 , input , " " );
478+ var parts = std .mem .splitSequence (u8 , input , " " );
479479 const command = parts .next () orelse return .BLOCKED ;
480480
481481 // Validate command name (alphanumeric and hyphens only)
@@ -520,13 +520,13 @@ pub const InputSanitizer = struct {
520520
521521 for (input ) | char | {
522522 switch (char ) {
523- '"' = > try escaped .appendSlice ("\\ \" " ),
524- '\\ ' = > try escaped .appendSlice ("\\\\ " ),
525- '\n ' = > try escaped .appendSlice ("\\ n" ),
526- '\r ' = > try escaped .appendSlice ("\\ r" ),
527- '\t ' = > try escaped .appendSlice ("\\ t" ),
523+ '"' = > try escaped .appendSlice (self . allocator , "\\ \" " ),
524+ '\\ ' = > try escaped .appendSlice (self . allocator , "\\\\ " ),
525+ '\n ' = > try escaped .appendSlice (self . allocator , "\\ n" ),
526+ '\r ' = > try escaped .appendSlice (self . allocator , "\\ r" ),
527+ '\t ' = > try escaped .appendSlice (self . allocator , "\\ t" ),
528528 0... 8, 11... 12, 14... 31, 127... 255 = > {
529- try escaped .writer ().print ("\\ x{X:0>2}" , .{char });
529+ try escaped .writer (self . allocator ).print ("\\ x{X:0>2}" , .{char });
530530 },
531531 else = > try escaped .append (self .allocator , char ),
532532 }
@@ -559,7 +559,7 @@ pub const InputSanitizer = struct {
559559
560560 // Phase 3: Pattern combination analysis
561561 if (suspicion_score >= 3.0 ) {
562- try result .blocked_patterns .append (try self .allocator .dupe (u8 , "Multiple suspicious patterns detected" ));
562+ try result .blocked_patterns .append (self . allocator , try self .allocator .dupe (u8 , "Multiple suspicious patterns detected" ));
563563 return .BLOCKED ;
564564 }
565565
@@ -592,10 +592,10 @@ pub const InputSanitizer = struct {
592592 }
593593
594594 if (url_encoded_count > input .len / 4 ) {
595- try result .blocked_patterns .append (try std .fmt .allocPrint (self .allocator , "Excessive URL encoding: {d} encoded chars" , .{url_encoded_count }));
595+ try result .blocked_patterns .append (self . allocator , try std .fmt .allocPrint (self .allocator , "Excessive URL encoding: {d} encoded chars" , .{url_encoded_count }));
596596 return .BLOCKED ;
597597 } else if (url_encoded_count > 5 ) {
598- try result .warnings .append (try std .fmt .allocPrint (self .allocator , "URL encoding detected: {d} chars" , .{url_encoded_count }));
598+ try result .warnings .append (self . allocator , try std .fmt .allocPrint (self .allocator , "URL encoding detected: {d} chars" , .{url_encoded_count }));
599599 encoding_level = .SUSPICIOUS ;
600600 }
601601
@@ -613,7 +613,7 @@ pub const InputSanitizer = struct {
613613 }
614614
615615 if (hex_count > 3 ) {
616- try result .warnings .append (try std .fmt .allocPrint (self .allocator , "Multiple hex patterns: {d}" , .{hex_count }));
616+ try result .warnings .append (self . allocator , try std .fmt .allocPrint (self .allocator , "Multiple hex patterns: {d}" , .{hex_count }));
617617 encoding_level = .SUSPICIOUS ;
618618 }
619619 }
@@ -627,7 +627,7 @@ pub const InputSanitizer = struct {
627627
628628 // Analyze command-like structures
629629 if (input .len > 0 and (input [0 ] == '/' or input [0 ] == '\\ ' or input [0 ] == '.' )) {
630- try result .warnings .append (try self .allocator .dupe (u8 , "Path-like input detected" ));
630+ try result .warnings .append (self . allocator , try self .allocator .dupe (u8 , "Path-like input detected" ));
631631 context_level = .SUSPICIOUS ;
632632 }
633633
@@ -646,7 +646,7 @@ pub const InputSanitizer = struct {
646646 }
647647
648648 if (bracket_count > 4 and paren_count > 2 ) {
649- try result .warnings .append (try self .allocator .dupe (u8 , "Script-like structure detected" ));
649+ try result .warnings .append (self . allocator , try self .allocator .dupe (u8 , "Script-like structure detected" ));
650650 context_level = .SUSPICIOUS ;
651651 }
652652
@@ -661,7 +661,7 @@ pub const InputSanitizer = struct {
661661 }
662662
663663 if (sql_keyword_count >= 2 ) {
664- try result .blocked_patterns .append (try self .allocator .dupe (u8 , "SQL-like command structure detected" ));
664+ try result .blocked_patterns .append (self . allocator , try self .allocator .dupe (u8 , "SQL-like command structure detected" ));
665665 return .BLOCKED ;
666666 }
667667
@@ -683,18 +683,18 @@ pub const InputSanitizer = struct {
683683 // Check for excessive repetition of any character
684684 for (char_freq , 0.. ) | freq , char | {
685685 if (freq > input .len / 2 and freq > 10 ) {
686- try result .warnings .append (try std .fmt .allocPrint (self .allocator , "Excessive character repetition: '{c}' appears {d} times" , .{ @as (u8 , @intCast (char )), freq }));
686+ try result .warnings .append (self . allocator , try std .fmt .allocPrint (self .allocator , "Excessive character repetition: '{c}' appears {d} times" , .{ @as (u8 , @intCast (char )), freq }));
687687 stats_level = .SUSPICIOUS ;
688688 }
689689 }
690690
691691 // Entropy analysis (simplified)
692692 const entropy = self .calculateEntropy (input );
693693 if (entropy < 1.0 ) {
694- try result .warnings .append (try std .fmt .allocPrint (self .allocator , "Low entropy input: {d:.2}" , .{entropy }));
694+ try result .warnings .append (self . allocator , try std .fmt .allocPrint (self .allocator , "Low entropy input: {d:.2}" , .{entropy }));
695695 stats_level = .SUSPICIOUS ;
696696 } else if (entropy > 7.0 ) {
697- try result .warnings .append (try std .fmt .allocPrint (self .allocator , "High entropy input (possible encoded): {d:.2}" , .{entropy }));
697+ try result .warnings .append (self . allocator , try std .fmt .allocPrint (self .allocator , "High entropy input (possible encoded): {d:.2}" , .{entropy }));
698698 stats_level = .SUSPICIOUS ;
699699 }
700700
@@ -710,12 +710,12 @@ pub const InputSanitizer = struct {
710710 }
711711
712712 if (space_count < input .len / 20 ) { // Very few spaces in long input
713- try result .warnings .append (try self .allocator .dupe (u8 , "Long input with minimal spacing (possible obfuscation)" ));
713+ try result .warnings .append (self . allocator , try self .allocator .dupe (u8 , "Long input with minimal spacing (possible obfuscation)" ));
714714 stats_level = .SUSPICIOUS ;
715715 }
716716
717717 if (special_char_count > input .len / 3 ) { // Too many special characters
718- try result .warnings .append (try self .allocator .dupe (u8 , "High special character density" ));
718+ try result .warnings .append (self . allocator , try self .allocator .dupe (u8 , "High special character density" ));
719719 stats_level = .SUSPICIOUS ;
720720 }
721721 }
@@ -738,7 +738,7 @@ pub const InputSanitizer = struct {
738738
739739 for (script_variations ) | variation | {
740740 if (std .mem .indexOf (u8 , input , variation )) | _ | {
741- try result .blocked_patterns .append (try std .fmt .allocPrint (self .allocator , "Obfuscated script pattern: {s}" , .{variation }));
741+ try result .blocked_patterns .append (self . allocator , try std .fmt .allocPrint (self .allocator , "Obfuscated script pattern: {s}" , .{variation }));
742742 return .BLOCKED ;
743743 }
744744 }
@@ -753,7 +753,7 @@ pub const InputSanitizer = struct {
753753
754754 for (cmd_patterns ) | pattern | {
755755 if (std .mem .indexOf (u8 , input , pattern )) | _ | {
756- try result .warnings .append (try std .fmt .allocPrint (self .allocator , "Spaced command pattern: {s}" , .{pattern }));
756+ try result .warnings .append (self . allocator , try std .fmt .allocPrint (self .allocator , "Spaced command pattern: {s}" , .{pattern }));
757757 fuzzy_level = .DANGEROUS ;
758758 }
759759 }
0 commit comments