From fed45c90ee48e6f8984853d44460b2579db9287d Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Sat, 28 May 2022 17:57:35 -0700 Subject: [PATCH] tolerate unwrapped xml response values --- src/aws.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/aws.zig b/src/aws.zig index 83f6e95..b272ee7 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -372,7 +372,16 @@ pub fn Request(comptime action: anytype) type { // // Big thing is that requestid, which we'll need to fetch "manually" const xml_options = xml_shaper.ParseOptions{ .allocator = options.client.allocator }; - const parsed = try xml_shaper.parse(action.Response, result.body, xml_options); + var body: []const u8 = result.body; + var free_body = false; + if (std.mem.lastIndexOf(u8, result.body[result.body.len - 20 ..], "Response>") == null) { + free_body = true; + // chop the "" from the front + const start = if (std.mem.indexOf(u8, result.body, "?>")) |i| i else 0; + body = try std.fmt.allocPrint(options.client.allocator, "{s}", .{body[start..]}); + } + defer if (free_body) options.client.allocator.free(body); + const parsed = try xml_shaper.parse(action.Response, body, xml_options); errdefer parsed.deinit(); var free_rid = false; // This needs to get into FullResponseType somehow: defer parsed.deinit();