travisstaloch / simdjzon

simdjson port to zig

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parser assumes all slices are strings

FreerGit opened this issue · comments

commented
const std = @import("std");
const dom = @import("src/dom.zig");

test {
    const allocator = std.testing.allocator;

    const T = struct { xs: []struct { a: u8 } };

    const input =
        \\{ "xs": [
        \\{"a": 42}
        \\]}
    ;

    var parser = try dom.Parser.initFixedBuffer(allocator, input, .{});
    defer parser.deinit();
    try parser.parse();

    var s: T = undefined;
    try parser.element().get(&s);

    std.debug.print("\n{} \n", .{s});
}

The parser will fail, expecting the [{...}] to be a string.

thanks for the report!

addressed in a74016e

please let me know if there are any other issues (as i'm sure there will be). or if satisfies your needs, you may close it.

Oh i should describe what i changed. I added a dom.Element.get_alloc() method which accepts a user allocator. its the same as get() but can handle non-string slice types.

Previous fix was incomplete and only worked for objects with 1 field.

Addressed in acd573f which also added more complete tests.

Should be actually fixed now 🙂

commented

Cloned latest main and works perfectly. Closing this :)