Commit d8b5831dc4

Chris Boesch <48591413+chrboesch@users.noreply.github.com>
2023-12-26 16:30:44
Fixed verbatim copy of trailing '%' in unescapeStr
1 parent f49a8c5
Changed files (1)
lib
lib/std/Uri.zig
@@ -90,6 +90,8 @@ pub fn unescapeString(allocator: std.mem.Allocator, input: []const u8) error{Out
                 };
                 inptr += 2;
                 outsize += 1;
+            } else {
+                outsize += 1;
             }
         } else {
             inptr += 1;
@@ -116,6 +118,9 @@ pub fn unescapeString(allocator: std.mem.Allocator, input: []const u8) error{Out
 
                 inptr += 2;
                 outptr += 1;
+            } else {
+                output[outptr] = input[inptr - 1];
+                outptr += 1;
             }
         } else {
             output[outptr] = input[inptr];
@@ -758,6 +763,10 @@ test "URI unescaping" {
     defer std.testing.allocator.free(actual);
 
     try std.testing.expectEqualSlices(u8, expected, actual);
+
+    const decoded = try unescapeString(std.testing.allocator, "/abc%");
+    defer std.testing.allocator.free(decoded);
+    try std.testing.expectEqualStrings("/abc%", decoded);
 }
 
 test "URI query escaping" {