{"action":"closed","issue":{"url":"https://api.github.com/repos/CESNET/libyang/issues/612","repository_url":"https://api.github.com/repos/CESNET/libyang","labels_url":"https://api.github.com/repos/CESNET/libyang/issues/612/labels{/name}","comments_url":"https://api.github.com/repos/CESNET/libyang/issues/612/comments","events_url":"https://api.github.com/repos/CESNET/libyang/issues/612/events","html_url":"https://github.com/CESNET/libyang/issues/612","id":359726160,"node_id":"MDU6SXNzdWUzNTk3MjYxNjA=","number":612,"title":"unique is not checked if the list instances are not sibling","user":{"login":"fanchanghu","id":16359351,"node_id":"MDQ6VXNlcjE2MzU5MzUx","avatar_url":"https://avatars1.githubusercontent.com/u/16359351?v=4","gravatar_id":"","url":"https://api.github.com/users/fanchanghu","html_url":"https://github.com/fanchanghu","followers_url":"https://api.github.com/users/fanchanghu/followers","following_url":"https://api.github.com/users/fanchanghu/following{/other_user}","gists_url":"https://api.github.com/users/fanchanghu/gists{/gist_id}","starred_url":"https://api.github.com/users/fanchanghu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fanchanghu/subscriptions","organizations_url":"https://api.github.com/users/fanchanghu/orgs","repos_url":"https://api.github.com/users/fanchanghu/repos","events_url":"https://api.github.com/users/fanchanghu/events{/privacy}","received_events_url":"https://api.github.com/users/fanchanghu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-13T03:11:17Z","updated_at":"2018-09-19T08:56:23Z","closed_at":"2018-09-19T08:56:23Z","author_association":"CONTRIBUTOR","body":"Hi,\r\n`unique` constraint is not checked if the list instances are not sibling, following code can reproduce this issue:\r\n```\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <assert.h>\r\n\r\n#include \"libyang/libyang.h\"\r\n\r\nstatic const char *yang =\r\n        R\"(\r\nmodule ListLeaf {\r\n    namespace \"http://example.net/zte/list/leaf\";\r\n    prefix ListLeaf;\r\n\r\n    container X {\r\n        list A{\r\n            key f1;\r\n            leaf f1{ type string; }\r\n            list B{\r\n                key f1;\r\n                unique f2;\r\n                leaf f1{ type string; }\r\n                leaf f2{ type string; }\r\n            }\r\n        } \r\n    }\r\n}\r\n)\";\r\n\r\nconst char *d = R\"({\r\n    \"ListLeaf:X\":{\r\n        \"A\":[\r\n            {\r\n                \"f1\":\"a\",\r\n                \"B\":[\r\n                    {\r\n                        \"f1\":\"a\",\r\n                        \"f2\":\"1\"\r\n                    }\r\n                ]\r\n            },\r\n            {\r\n                \"f1\":\"b\",\r\n                \"B\":[\r\n                    {\r\n                        \"f1\":\"a\",\r\n                        \"f2\":\"1\"\r\n                    }\r\n                ]\r\n            }\r\n        ]\r\n    }\r\n})\";\r\n\r\nint main(void)\r\n{\r\n    int rc;\r\n    const struct lys_module *mod;\r\n    struct ly_ctx *ctx;\r\n    struct lyd_node *dt;\r\n\r\n    ctx = ly_ctx_new(NULL, 0);\r\n    assert(ctx);\r\n\r\n    mod = lys_parse_mem(ctx, yang, LYS_IN_YANG);\r\n    assert(mod);\r\n\r\n    dt = lyd_parse_mem(ctx, d, LYD_JSON, LYD_OPT_CONFIG, NULL);\r\n    assert(dt);\r\n    lyd_free(dt);\r\n\r\n    ly_ctx_destroy(ctx, NULL);\r\n\r\n    return 0;\r\n}\r\n```\r\nAn error should be detected in the line `dt = lyd_parse_mem(ctx, d, LYD_JSON, LYD_OPT_CONFIG, NULL);` but not."}}
{"actor":{"display_login":"michalvasko"}}