diff --git a/includes/std/ctype.pat b/includes/std/ctype.pat index 30f1881..82f49b9 100644 --- a/includes/std/ctype.pat +++ b/includes/std/ctype.pat @@ -85,7 +85,7 @@ namespace auto std::ctype { @return True if `c` is part of this range, false otherwise */ fn isprint(char c) { - return c >= '0' && c <= '~'; + return c >= ' ' && c <= '~'; }; /** diff --git a/patterns/bencode.hexpat b/patterns/bencode.hexpat index 070aab9..9f66ba7 100644 --- a/patterns/bencode.hexpat +++ b/patterns/bencode.hexpat @@ -38,10 +38,15 @@ namespace bencode { ASCIIDecimal length; char separator [[hidden]]; char value[length]; - } [[sealed, format("bencode::format_string"), transform("bencode::format_string")]]; + } [[sealed, format("bencode::format_string")]]; fn format_string(String string) { - return string.value; + for (u64 i = 0, i < string.length, i = i + 1) { + if (!std::ctype::isprint(string.value[i])) { + return "Contains non-printable characters"; + } + } + return std::format("\"{}\"", string.value); }; using Bencode; @@ -57,6 +62,10 @@ namespace bencode { if (type == Type::Dictionary) { DictionaryEntry entry[while(std::mem::read_unsigned($, 1) != 'e')]; + char end; + } else if (type == Type::List) { + Value entry[while(std::mem::read_unsigned($, 1) != 'e')]; + char end; } else if (type == Type::Integer) { ASCIIDecimal value; char end;