Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/xmlnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ bool XmlNode::isComment() const

std::string XmlNode::name() const
{
if (mPimpl->mXmlNodePtr->name == nullptr) {
return {};
}
return reinterpret_cast<const char *>(mPimpl->mXmlNodePtr->name);
}

Expand Down Expand Up @@ -313,7 +316,7 @@ std::string XmlNode::convertToString() const
xmlKeepBlanksDefault(1);
xmlBufferPtr buffer = xmlBufferCreate();
xmlNodeDump(buffer, mPimpl->mXmlNodePtr->doc, mPimpl->mXmlNodePtr, 0, 0);
std::string contentString = std::string(reinterpret_cast<const char *>(buffer->content));
std::string contentString = std::string(reinterpret_cast<const char *>(xmlBufferContent(buffer)));
xmlBufferFree(buffer);
return contentString;
}
Expand Down
2 changes: 1 addition & 1 deletion src/xmlutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ XmlNamespaceMap traverseTreeForElementNamespaces(const XmlNodePtr &node)
XmlNamespaceMap nodeNamespaceMap;
auto tempNode = node;
while (tempNode != nullptr) {
if (!tempNode->isText() && !tempNode->isComment()) {
if (tempNode->isElement()) {
nodeNamespaceMap.emplace(tempNode->name(), tempNode->namespaceUri());
}

Expand Down
32 changes: 32 additions & 0 deletions tests/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,38 @@ TEST(Parser, invalidModelElement)
EXPECT_EQ_ISSUES(expectedIssues, p);
}

TEST(Parser, invalidRootNodeWithCdataSection)
{
const std::string in =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<svg xmlns=\"http://www.w3.org/2000/svg\">\n"
" <metadata><![CDATA[Some metadata.]]></metadata>\n"
"</svg>\n";
const std::vector<std::string> expectedIssues = {
"Model element is of invalid type 'svg'. A valid CellML root node should be of type 'model'.",
};

libcellml::ParserPtr p = libcellml::Parser::create();
p->parseModel(in);
EXPECT_EQ_ISSUES(expectedIssues, p);
}

TEST(Parser, invalidModelElementWithCdataSection)
{
const std::string in =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<model xmlns=\"http://www.cellml.org/cellml/2.0#\" name=\"model_name\">\n"
" <![CDATA[Some data.]]>\n"
"</model>\n";
const std::vector<std::string> expectedIssues = {
"Model 'model_name' has an invalid child element ''.",
};

libcellml::ParserPtr p = libcellml::Parser::create();
p->parseModel(in);
EXPECT_EQ_ISSUES(expectedIssues, p);
}

TEST(Parser, modelWithInvalidElement)
{
const std::string in1 =
Expand Down
Loading