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]) } } }