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

This commit is contained in:
AnnikaCodes
2023-07-27 10:18:48 -07:00
committed by GitHub
parent 2dd7c6b268
commit 775da34268

View File

@@ -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);
}