From 775da34268b8133eae47c1840a38e922189dc0f1 Mon Sep 17 00:00:00 2001 From: AnnikaCodes Date: Thu, 27 Jul 2023 10:18:48 -0700 Subject: [PATCH] std.Uri: Don't double-escape escaped query parameters (#16043) --- lib/std/Uri.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/std/Uri.zig b/lib/std/Uri.zig index 2228c78120..1a2993f174 100644 --- a/lib/std/Uri.zig +++ b/lib/std/Uri.zig @@ -443,7 +443,7 @@ fn isPathChar(c: u8) bool { } fn isQueryChar(c: u8) bool { - return isPathChar(c) or c == '?'; + return isPathChar(c) or c == '?' or c == '%'; } fn isQuerySeparator(c: u8) bool { @@ -672,3 +672,13 @@ test "URI unescaping" { try std.testing.expectEqualSlices(u8, expected, actual); } + +test "URI query escaping" { + const address = "https://objects.githubusercontent.com/?response-content-type=application%2Foctet-stream"; + const parsed = try Uri.parse(address); + + // format the URI to escape it + const formatted_uri = try std.fmt.allocPrint(std.testing.allocator, "{}", .{parsed}); + defer std.testing.allocator.free(formatted_uri); + try std.testing.expectEqualStrings("/?response-content-type=application%2Foctet-stream", formatted_uri); +}