[mapguide-commits] r10292 - branches/4.0/MgDev/Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Nov 18 07:27:17 PST 2026


Author: jng
Date: 2026-11-18 07:27:17 -0800 (Wed, 18 Nov 2026)
New Revision: 10292

Modified:
   branches/4.0/MgDev/Server/src/UnitTesting/TestSelection.cpp
Log:
Gracefully handle malformed XML in MgSelection. Fixes #2904

Modified: branches/4.0/MgDev/Server/src/UnitTesting/TestSelection.cpp
===================================================================
--- branches/4.0/MgDev/Server/src/UnitTesting/TestSelection.cpp	2026-11-18 15:26:37 UTC (rev 10291)
+++ branches/4.0/MgDev/Server/src/UnitTesting/TestSelection.cpp	2026-11-18 15:27:17 UTC (rev 10292)
@@ -16,7 +16,7 @@
 //
 
 #include "MapGuideCommon.h"
-#include "catch.hpp"
+#include "CatchHelperMacros.h"
 
 #include <Fdo.h>
 #include <utility>
@@ -238,3 +238,46 @@
         FAIL("Generating a selection filter threw");
     }
 }
+
+// A selection string arrives as client input: the viewer round-trips its own selection XML through
+// it, and the samples take the string straight off the query string. Whatever cannot be parsed has
+// to come back as an MgException. It did not - FromXml asked for the document's root element after
+// the parser had already rejected the document, so the root was NULL and
+// MgXmlUtil::GetFirstChild dereferenced it. A request that should fail instead takes the whole
+// process down, which on a shared server is a crash any client can ask for.
+//
+// Nothing here needs a map, a session or a feature source: FromXml works from the string alone,
+// which is why a selection can be built over a map that has no connection behind it.
+TEST_CASE("SelectionRejectsMalformedXml", "[Selection]")
+{
+    SECTION("A selection that is not XML is reported as an XML parser error")
+    {
+        Ptr<MgSelectionBase> selection = new MgSelectionBase();
+        REQUIRE_THROWS_MG(selection->FromXml(L"not<xml"), MgXmlParserException);
+    }
+
+    // The constructor the Java, .NET and PHP bindings expose is the reported entry point.
+    SECTION("The binding constructor reports it the same way")
+    {
+        Ptr<MgMap> map = new MgMap();
+        REQUIRE_THROWS_MG(new MgSelection(map, L"not<xml"), MgXmlParserException);
+    }
+
+    // An empty selection is the documented "nothing is selected" case, and it is what the viewer
+    // sends when the selection is cleared, so rejecting malformed XML must not turn it into an
+    // error as well.
+    SECTION("An empty selection stays a no-op")
+    {
+        try
+        {
+            Ptr<MgSelectionBase> selection = new MgSelectionBase();
+            selection->FromXml(L"");
+            CHECK(selection->ToXml().find(L"<Layer") == STRING::npos);
+        }
+        catch (MgException* e)
+        {
+            e->Release();
+            FAIL("FromXml rejected an empty selection");
+        }
+    }
+}



More information about the mapguide-commits mailing list