Skip to content

Commit

Permalink
Merge pull request #401 from mtconnect/empty_cdata_xml_generation_fix
Browse files Browse the repository at this point in the history
Empty cdata xml generation fix
  • Loading branch information
wsobel authored Jan 22, 2024
2 parents 298c4e2 + c95972e commit c0906af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(AGENT_VERSION_MAJOR 2)
set(AGENT_VERSION_MINOR 2)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 16)
set(AGENT_VERSION_BUILD 17)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
9 changes: 6 additions & 3 deletions src/mtconnect/entity/xml_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,21 @@ namespace mtconnect {
if (p.first == "VALUE")
{
// The value is the content for a simple element
THROW_IF_XML2_ERROR(xmlTextWriterWriteString(writer, BAD_CAST s));
if (*s != '\0')
THROW_IF_XML2_ERROR(xmlTextWriterWriteString(writer, BAD_CAST s));
}
else if (p.first == "RAW")
{
THROW_IF_XML2_ERROR(xmlTextWriterWriteRaw(writer, BAD_CAST s));
if (*s != '\0')
THROW_IF_XML2_ERROR(xmlTextWriterWriteRaw(writer, BAD_CAST s));
}
else
{
QName name(p.first);
string qname = stripUndeclaredNamespace(name, namespaces);
AutoElement element(writer, qname);
THROW_IF_XML2_ERROR(xmlTextWriterWriteString(writer, BAD_CAST s));
if (*s != '\0')
THROW_IF_XML2_ERROR(xmlTextWriterWriteString(writer, BAD_CAST s));
}
}

Expand Down
22 changes: 22 additions & 0 deletions test_package/agent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3000,3 +3000,25 @@ TEST_F(AgentTest, device_should_have_hash_for_2_2)
ASSERT_XML_PATH_EQUAL(doc, "//m:DeviceAdded[3]@hash", (*di)->get<string>("hash").c_str());
}
}

TEST_F(AgentTest, should_not_add_spaces_to_output)
{
addAdapter();

m_agentTestHelper->m_adapter->processData("2024-01-22T20:00:00Z|program|");
m_agentTestHelper->m_adapter->processData("2024-01-22T20:00:00Z|block|");

{
PARSE_XML_RESPONSE("/current");
ASSERT_XML_PATH_EQUAL(doc, "//m:DeviceStream//m:Program", "");
ASSERT_XML_PATH_EQUAL(doc, "//m:DeviceStream//m:Block", "");
}

m_agentTestHelper->m_adapter->processData("2024-01-22T20:00:00Z|program| |block| ");

{
PARSE_XML_RESPONSE("/current");
ASSERT_XML_PATH_EQUAL(doc, "//m:DeviceStream//m:Program", "");
ASSERT_XML_PATH_EQUAL(doc, "//m:DeviceStream//m:Block", "");
}
}

0 comments on commit c0906af

Please sign in to comment.