fix snake case comparison

code in the function required found variable to be a real count
for allocation purposes, but it was originally coded as a flag
instead, which broke any field with more than two underscores
This commit is contained in:
Emil Lerch 2021-06-23 18:16:54 -07:00
parent f816c0cbf1
commit 3d9490de82
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -1480,10 +1480,8 @@ fn snakeCaseComp(field: []const u8, key: []const u8, options: ParseOptions) !boo
// Then compare // Then compare
var found: u32 = 0; var found: u32 = 0;
for (field) |ch| { for (field) |ch| {
if (ch == '_') { if (ch == '_')
found = found + 1; found = found + 1;
break;
}
} }
if (found == 0) if (found == 0)
return std.mem.eql(u8, field, key); return std.mem.eql(u8, field, key);
@ -1515,6 +1513,11 @@ fn snakeCaseComp(field: []const u8, key: []const u8, options: ParseOptions) !boo
} }
inx = inx + 1; inx = inx + 1;
} }
// std.debug.print("comp_field, len {d}: {s}\n", .{ comp_field.len, comp_field });
// std.debug.print("normalized_key, len {d}: {s}\n", .{ normalized_key.len, normalized_key });
// std.debug.print("comp_field, last: {d}\n", .{comp_field[comp_field.len - 1]});
// std.debug.print("normalized_key, last: {d}\n", .{normalized_key[normalized_key.len - 1]});
return std.mem.eql(u8, comp_field, normalized_key); return std.mem.eql(u8, comp_field, normalized_key);
} }