query: expand: fix a bug in inLinks

Old codes handle links incorrectly; when links appear before some
keys, old codes don't expand these keys.

Tested:
1. On real hardware, Expand with links are working correctly.
2. Unit tests.

Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I028b55579d833f23120987a24cef4442fdd5800d
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index 042451f..b4a18a3 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -389,18 +389,19 @@
     // Loop the object and look for links
     for (auto& element : *obj)
     {
-        if (!inLinks)
+        bool localInLinks = inLinks;
+        if (!localInLinks)
         {
             // Check if this is a links node
-            inLinks = element.first == "Links";
+            localInLinks = element.first == "Links";
         }
         // Only traverse the parts of the tree the user asked for
         // Per section 7.3 of the redfish specification
-        if (inLinks && eType == ExpandType::NotLinks)
+        if (localInLinks && eType == ExpandType::NotLinks)
         {
             continue;
         }
-        if (!inLinks && eType == ExpandType::Links)
+        if (!localInLinks && eType == ExpandType::Links)
         {
             continue;
         }
@@ -408,7 +409,7 @@
         BMCWEB_LOG_DEBUG << "Traversing response at " << newPtr;
 
         findNavigationReferencesRecursive(eType, element.second, newPtr,
-                                          inLinks, out);
+                                          localInLinks, out);
     }
 }
 
diff --git a/redfish-core/include/utils/query_param_test.cpp b/redfish-core/include/utils/query_param_test.cpp
index 7897807..e5d8de7 100644
--- a/redfish-core/include/utils/query_param_test.cpp
+++ b/redfish-core/include/utils/query_param_test.cpp
@@ -302,4 +302,12 @@
     EXPECT_TRUE(findNavigationReferences(ExpandType::NotLinks, singleLinkNode,
                                          json::json_pointer(""))
                     .empty());
+
+    json multiTreeNodes =
+        R"({"Links": {"@odata.id": "/links"}, "Foo" : {"@odata.id": "/foobar"}})"_json;
+    // Should still find Foo
+    EXPECT_THAT(findNavigationReferences(ExpandType::NotLinks, multiTreeNodes,
+                                         json::json_pointer("")),
+                UnorderedElementsAre(redfish::query_param::ExpandNode{
+                    json::json_pointer("/Foo"), "/foobar"}));
 }