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);
             }
diff --git a/tests/interpreter.cpp b/tests/interpreter.cpp
index b296ca1..3acef2b 100644
--- a/tests/interpreter.cpp
+++ b/tests/interpreter.cpp
@@ -54,6 +54,26 @@
                 expectedPath = dataPath_{};
             }
 
+            SECTION("arg: ..")
+            {
+                lsArg = dataPath_{Scope::Relative, {dataNode_{nodeup_{}}}};
+                expectedPath = dataPath_{};
+            }
+
+            SECTION("arg: /..")
+            {
+                lsArg = dataPath_{Scope::Absolute, {dataNode_{nodeup_{}}}};
+                expectedPath = dataPath_{Scope::Absolute, {}};
+            }
+
+            SECTION("arg: /example:a/../example:a")
+            {
+                lsArg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}},
+                                                    {nodeup_{}},
+                                                    {module_{"example"}, container_{"a"}}}};
+                expectedPath = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}};
+            }
+
             SECTION("arg: example:a")
             {
                 lsArg = dataPath_{Scope::Relative, {{module_{"example"}, container_{"a"}}}};