diff options
| author | AnnikaCodes <annika@worldbrightening.net> | 2023-07-27 10:18:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-27 13:18:48 -0400 |
| commit | 775da34268b8133eae47c1840a38e922189dc0f1 (patch) | |
| tree | 93bf6e8b24a1a00de6a19db54f1b619b3b5d7165 /lib/std/Uri.zig | |
| parent | 2dd7c6b268a838d4a130ac2eb88f4267598bb42e (diff) | |
| download | zig-775da34268b8133eae47c1840a38e922189dc0f1.tar.gz zig-775da34268b8133eae47c1840a38e922189dc0f1.zip | |
std.Uri: Don't double-escape escaped query parameters (#16043)
Diffstat (limited to 'lib/std/Uri.zig')
| -rw-r--r-- | lib/std/Uri.zig | 12 |
1 files changed, 11 insertions, 1 deletions
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); +} |
