Fix StaticSchema::lastNodeOfSchemaPath

This if branch was never used in any test, so the bug never came up.

Change-Id: I785600076df8aea7d8169b020d0bda65f5b74ae4
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 4964e8e..3eb42f6 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -116,17 +116,9 @@
 std::string lastNodeOfSchemaPath(const std::string& path)
 {
     std::string res = path;
-    auto pos = res.find_last_of('/');
-    if (pos == 0) { // path had only one path fragment - "/something:something"
-        res.erase(0, 1);
-        return res;
+    if (auto pos = res.find_last_of('/'); pos != res.npos) {
+        res.erase(0, pos + 1);
     }
-    if (pos != res.npos) { // path had more fragments
-        res.erase(0, pos);
-        return res;
-    }
-
-    // path was empty
     return res;
 }
 
diff --git a/tests/leaf_editing.cpp b/tests/leaf_editing.cpp
index ca720c5..9ce5c35 100644
--- a/tests/leaf_editing.cpp
+++ b/tests/leaf_editing.cpp
@@ -52,6 +52,7 @@
     schema->addLeaf("/mod:list", "mod:leafInList", yang::String{});
     schema->addLeaf("/", "mod:refToString", yang::LeafRef{"/mod:leafString", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:leafString"))});
     schema->addLeaf("/", "mod:refToInt8", yang::LeafRef{"/mod:leafInt8", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:leafInt8"))});
+    schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:contA/mod:identInCont"))});
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
@@ -314,6 +315,13 @@
                     expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")});
                     expected.m_data = int8_t{42};
                 }
+
+                SECTION("refToLeafInCont")
+                {
+                    input = "set mod:refToLeafInCont pizza";
+                    expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToLeafInCont")});
+                    expected.m_data = identityRef_{"pizza"};
+                }
             }
         }