MartinKoch123 / yaml

MATLAB YAML parser and emitter based on SnakeYAML
MIT License
22 stars 7 forks source link

ConvertToArray tries to concatenate dissimilar structs #15

Closed AdamCooman closed 2 weeks ago

AdamCooman commented 4 weeks ago

When an array in yaml has structs with different fields, the code crashes when ConvertToArray is true. Basically, the elementsHaveConsistentType forgets to check that structs have matching fields.

To reproduce the bug, you can run the following matlab code:

% two dissimilar structs inside a cell array
data = {struct("a",1) struct("b",2)};
% dump to yaml and load back in
yaml_str = yaml.dump(data);
data_test = yaml.load(yaml_str,ConvertToArray=true);

which will generate the following error:

Error using horzcat
Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays
requires that these arrays have the same set of fields.

Error in yaml.load/convertList (line 111)
            result = horzcat(result{:});

Error in yaml.load/convert (line 71)
                result = convertList(node);

Error in yaml.load (line 48)
    result = convert(rootNode);

Error in untitled (line 10)
data_test = yaml.load(yaml_str,ConvertToArray=true);
MartinKoch123 commented 2 weeks ago

Thanks for reporting, I fixed it