diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/input/pack/xml_file.xml b/xml_converter/integration_tests/test_cases/category_name_invalid/input/pack/xml_file.xml
new file mode 100644
index 00000000..7ae0a3fb
--- /dev/null
+++ b/xml_converter/integration_tests/test_cases/category_name_invalid/input/pack/xml_file.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/category_name_invalid/output_proto/markers.bin
new file mode 100644
index 00000000..e69de29b
diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml
new file mode 100644
index 00000000..d6de0503
--- /dev/null
+++ b/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml b/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml
new file mode 100644
index 00000000..3ca733b5
--- /dev/null
+++ b/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml
@@ -0,0 +1,13 @@
+input_paths:
+ "pack": "xml"
+expected_stdout: |
+ Error: Category attribute 'name' is missing or is an empty string when it should be a non-empty string
+ test_cases/category_name_invalid/input/pack/xml_file.xml
+ 2 |
+ | ^^^^^^^^^^^^^^
+ Error: Category attribute 'name' is missing or is an empty string when it should be a non-empty string
+ test_cases/category_name_invalid/input/pack/xml_file.xml
+ 3 |
+ | ^^^^^^^^^^^^^^
+expected_stderr: |
+expected_returncode: 0
diff --git a/xml_converter/src/packaging_xml.cpp b/xml_converter/src/packaging_xml.cpp
index 5efc42ab..44779ebd 100644
--- a/xml_converter/src/packaging_xml.cpp
+++ b/xml_converter/src/packaging_xml.cpp
@@ -13,8 +13,14 @@ using namespace std;
////////////////////////////////// SERIALIZE ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
+unsigned int UNKNOWN_CATEGORY_COUNTER = 0;
void parse_marker_categories(rapidxml::xml_node<>* node, map* marker_categories, vector* errors, string base_dir, int depth = 0) {
if (get_node_name(node) == "MarkerCategory") {
+ // TODO: Eventually this process should be removed. Instead we should be
+ // grabbing the name during the parsing of all the atrributes to
+ // avoid doing a secondary search through the attributes, and then
+ // we should have a method of applying the parsed node on top of
+ // its hirearchy probably using the is_set flags.
string name = lowercase(find_attribute_value(node, "name"));
XMLReaderState state = {
@@ -22,6 +28,12 @@ void parse_marker_categories(rapidxml::xml_node<>* node, map*
marker_categories,
};
+ if (name == "") {
+ errors->push_back(new XMLNodeNameError("Category attribute 'name' is missing or is an empty string when it should be a non-empty string", node));
+ name = "UNKNOWN_CATEGORY_" + to_string(UNKNOWN_CATEGORY_COUNTER);
+ UNKNOWN_CATEGORY_COUNTER++;
+ }
+
Category* this_category = &(*marker_categories)[name];
this_category->init_from_xml(node, errors, &state);
for (rapidxml::xml_node<>* child_node = node->first_node(); child_node; child_node = child_node->next_sibling()) {
diff --git a/xml_converter/src/rapid_helpers.cpp b/xml_converter/src/rapid_helpers.cpp
index 21d42b98..3b7c313c 100644
--- a/xml_converter/src/rapid_helpers.cpp
+++ b/xml_converter/src/rapid_helpers.cpp
@@ -9,8 +9,20 @@
using namespace std;
+////////////////////////////////////////////////////////////////////////////////
+// find_attribute_value (depricated)
+//
+// This function does a linear search over an xml node to try and find an
+// attribute with the specified name. It the attribute is not found then an
+// empty string is returned.
+//
+// This function is depricated and should not be used by any new code.
+////////////////////////////////////////////////////////////////////////////////
string find_attribute_value(rapidxml::xml_node<>* node, string attribute_name) {
- auto attribute = node->first_attribute(attribute_name.data(), attribute_name.size(), false);
+ rapidxml::xml_attribute* attribute = node->first_attribute(attribute_name.data(), attribute_name.size(), false);
+ if (attribute == nullptr) {
+ return "";
+ }
return string(attribute->value(), attribute->value_size());
}