From 652a04d0c31b3b42a3967d3d815608d6df04ff86 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Sat, 28 May 2022 18:02:31 -0700 Subject: [PATCH] handle greedy labels --- src/aws.zig | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/aws.zig b/src/aws.zig index 7ef00dd..51a97a3 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -539,19 +539,23 @@ fn buildPath(allocator: std.mem.Allocator, raw_uri: []const u8, comptime ActionR var buffer = try std.ArrayList(u8).initCapacity(allocator, raw_uri.len); // const writer = buffer.writer(); defer buffer.deinit(); - var in_var = false; + var in_label = false; var start: usize = 0; for (raw_uri) |c, inx| { switch (c) { '{' => { - in_var = true; + in_label = true; start = inx + 1; }, '}' => { - in_var = false; - const replacement_var = raw_uri[start..inx]; + in_label = false; + // The label may be "greedy" (uses a '+' at the end), but + // it's not clear if that effects this processing + var end = inx; + if (raw_uri[inx - 1] == '+') end -= 1; + const replacement_label = raw_uri[start..end]; inline for (std.meta.fields(ActionRequest)) |field| { - if (std.mem.eql(u8, request.fieldNameFor(field.name), replacement_var)) { + if (std.mem.eql(u8, request.fieldNameFor(field.name), replacement_label)) { var replacement_buffer = try std.ArrayList(u8).initCapacity(allocator, raw_uri.len); defer replacement_buffer.deinit(); var encoded_buffer = try std.ArrayList(u8).initCapacity(allocator, raw_uri.len); @@ -569,7 +573,7 @@ fn buildPath(allocator: std.mem.Allocator, raw_uri: []const u8, comptime ActionR } } }, - else => if (!in_var) { + else => if (!in_label) { try buffer.append(c); } else {}, }