From c7af2576f56ee31730fb41c96c6711c35c06321e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Tesa=C5=99?= Date: Wed, 5 Aug 2026 23:45:34 +0200 Subject: [PATCH] Zero-pad percent_encode escapes to two uppercase hex digits --- core/net/url.odin | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/net/url.odin b/core/net/url.odin index 29028b16c..1a8028ad0 100644 --- a/core/net/url.odin +++ b/core/net/url.odin @@ -114,6 +114,8 @@ join_url :: proc(scheme, host, path: string, queries: map[string]string, fragmen } percent_encode :: proc(s: string, allocator := context.allocator) -> string { + HEX_DIGITS_UPPER := "0123456789ABCDEF" // NOTE(michtesar): RFC 3986 ยง2.1 + b := strings.builder_make(allocator) strings.builder_grow(&b, len(s) + 16) // NOTE(tetra): A reasonable number to allow for the number of things we need to escape. @@ -124,10 +126,9 @@ percent_encode :: proc(s: string, allocator := context.allocator) -> string { case: bytes, n := utf8.encode_rune(ch) for byte in bytes[:n] { - buf: [2]u8 = --- - t := strconv.write_int(buf[:], i64(byte), 16) - strings.write_rune(&b, '%') - strings.write_string(&b, t) + strings.write_byte(&b, '%') + strings.write_byte(&b, HEX_DIGITS_UPPER[byte >> 4]) + strings.write_byte(&b, HEX_DIGITS_UPPER[byte & 0xF]) } } }