Fix sysrepo bug with key-less lists
More info on Github.
Bug: https://github.com/sysrepo/sysrepo/issues/2210
Change-Id: I87601a85dbd77d70634ade2069642eb9ceb075b1
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index cdaff49..f6e8d1d 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -219,7 +219,7 @@
try {
auto oldDs = m_session->session_get_ds();
m_session->session_switch_ds(SR_DS_OPERATIONAL);
- auto config = m_session->get_data(((path == "/") ? "/*" : path + "//.").c_str());
+ auto config = m_session->get_data(((path == "/") ? "/*" : path).c_str());
m_session->session_switch_ds(oldDs);
if (config) {
lyNodesToTree(res, config->tree_for());
diff --git a/tests/datastore_access.cpp b/tests/datastore_access.cpp
index cc97aa9..613f661 100644
--- a/tests/datastore_access.cpp
+++ b/tests/datastore_access.cpp
@@ -517,14 +517,28 @@
{
MockDataSupplier mockOpsData;
OperationalDataSubscription opsDataSub("example-schema", "/example-schema:temperature", mockOpsData);
+ OperationalDataSubscription opsDataSub2("example-schema", "/example-schema:users", mockOpsData);
DatastoreAccess::Tree expected;
std::string xpath;
+
SECTION("temperature")
{
expected = {{"/example-schema:temperature", int32_t{22}}};
xpath = "/example-schema:temperature";
}
+ SECTION("key-less lists")
+ {
+ expected = {
+ {"/example-schema:users/userList[1]", special_{SpecialValue::List}},
+ {"/example-schema:users/userList[1]/name", std::string{"John"}},
+ {"/example-schema:users/userList[1]/otherfield", std::string{"LOL"}},
+ {"/example-schema:users/userList[2]", special_{SpecialValue::List}},
+ {"/example-schema:users/userList[2]/name", std::string{"Foo"}},
+ {"/example-schema:users/userList[2]/otherfield", std::string{"Bar"}},
+ };
+ xpath = "/example-schema:users";
+ }
REQUIRE_CALL(mockOpsData, get_data(xpath)).RETURN(expected);
REQUIRE(datastore.getItems(xpath) == expected);
}
diff --git a/tests/example-schema.yang b/tests/example-schema.yang
index 372b83d..6c546d3 100644
--- a/tests/example-schema.yang
+++ b/tests/example-schema.yang
@@ -303,4 +303,17 @@
bit parity;
}
}
+
+ container users {
+ config false;
+ list userList {
+ leaf name {
+ type string;
+ }
+ leaf otherfield {
+ type string;
+ }
+ }
+ }
+
}