CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
367 stars 292 forks source link

Duplicate predicate key for distinct keys with matching first word #1922

Closed andrei-pavel closed 2 years ago

andrei-pavel commented 2 years ago

Trying to do a setItem and getting:

libyang[0]: Duplicate predicate key "identifier" in path.
N7sysrepo13ErrorWithCodeE, what: Session::setItem: Couldn't set '/kea-dhcp6-server:config/shared-networks[name='my-secret-network']/subnet6[id='1']/reservations[identifier-type='duid'][identifier='01:02:03:04:05:06:07:08:09:0A']/duid' to '01:02:03:04:05:06:07:08:09:0A': SR_ERR_INVAL_ARG

I think identifier-type is compared with identifier and it determines that they are equal? The following line seems relevant.

                    if (!strncmp(set->objs[i], name, name_len) && !isalpha(((char *)set->objs[i])[name_len])) {

isalpha seems to try to determine if the string ends at that length? But in this case it matches the dash?

Changing it to the following seems to fix the issue on my end, but causes libyang unit tests to fail.

                    if (name_len == strlen(set->objs[i]) && !strncmp(set->objs[i], name, name_len)) {
The following tests FAILED:
         29 - utest_instanceid (Failed)
         30 - utest_instanceid_valgrind (Failed)
         77 - utest_tree_schema_compile (Failed)
         78 - utest_tree_schema_compile_valgrind (Failed)

Using versions from master branches with C++ API, but reporting here because it seems to be a libyang issue.

    LIBYANG_VERSION:       2.0.231
    LIBYANGCPP_VERSION:    1.1.0
    SYSREPO_VERSION:       2.1.84
    SYSREPOCPP_VERSION:    1.1.0
michalvasko commented 2 years ago

Yes, the check should now be properly fixed.

andrei-pavel commented 2 years ago

Works on my end. Thank you!