authorgravatar for annika@worldbrightening.netAnnikaCodes <annika@worldbrightening.net> 2023-07-27 10:18:48-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-27 13:18:48-04:00
log775da34268b8133eae47c1840a38e922189dc0f1
tree93bf6e8b24a1a00de6a19db54f1b619b3b5d7165
parent2dd7c6b268a838d4a130ac2eb88f4267598bb42e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std.Uri: Don't double-escape escaped query parameters (#16043)


1 files changed, 11 insertions(+), 1 deletions(-)

lib/std/Uri.zig+11-1
......@@ -443,7 +443,7 @@ fn isPathChar(c: u8) bool {
443443}
444444
445445fn isQueryChar(c: u8) bool {
446 return isPathChar(c) or c == '?';
446 return isPathChar(c) or c == '?' or c == '%';
447447}
448448
449449fn isQuerySeparator(c: u8) bool {
......@@ -672,3 +672,13 @@ test "URI unescaping" {
672672
673673 try std.testing.expectEqualSlices(u8, expected, actual);
674674}
675
676test "URI query escaping" {
677 const address = "https://objects.githubusercontent.com/?response-content-type=application%2Foctet-stream";
678 const parsed = try Uri.parse(address);
679
680 // format the URI to escape it
681 const formatted_uri = try std.fmt.allocPrint(std.testing.allocator, "{}", .{parsed});
682 defer std.testing.allocator.free(formatted_uri);
683 try std.testing.expectEqualStrings("/?response-content-type=application%2Foctet-stream", formatted_uri);
684}