Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty cdata xml generation fix #401

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "");
}
}
Loading