Fix toCanonical going up from root
This is like a third place where I'm adding this .empty() check, I
should probably make a function that does this for me.
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/178
Change-Id: Iafc43df1d8fc882a1b27b9ce1c6c5ce663800e41
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index f2c0869..43fc329 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -275,12 +275,14 @@
}();
if (suffix.m_scope == Scope::Absolute) {
- return suffix;
+ res = {Scope::Absolute, {}};
}
for (const auto& fragment : suffix.m_nodes) {
if (std::holds_alternative<nodeup_>(fragment.m_suffix)) {
- res.m_nodes.pop_back();
+ if (!res.m_nodes.empty()) { // Allow going up, when already at root
+ res.m_nodes.pop_back();
+ }
} else {
res.m_nodes.push_back(fragment);
}