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
6 changes: 2 additions & 4 deletions source/MaterialXFormat/External/PugiXML/pugixml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3946,13 +3946,11 @@ PUGI__NS_BEGIN
++s;
break;
case '<':
// MaterialX: Allow angle brackets in MTLX serialization.
writer.write(*s);
writer.write('&', 'l', 't', ';');
++s;
break;
case '>':
// MaterialX: Allow angle brackets in MTLX serialization.
writer.write(*s);
writer.write('&', 'g', 't', ';');
++s;
break;
case '"':
Expand Down
35 changes: 35 additions & 0 deletions source/MaterialXTest/MaterialXFormat/XmlIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,38 @@ TEST_CASE("Locale region testing", "[xmlio]")
// Restore the original locale.
std::locale::global(origLocale);
}

TEST_CASE("XML strictness", "[xmlio]")
{
mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();
mx::DocumentPtr stdlib = mx::createDocument();
mx::loadLibraries({ "libraries" }, searchPath, stdlib);

mx::DocumentPtr doc = mx::createDocument();
doc->setDataLibrary(stdlib);

// Create image node with illegal <> characters
mx::NodePtr imageNode = doc->addNode("image", "testImage");
imageNode->addInputsFromNodeDef();
mx::InputPtr fileInput = imageNode->getInput("file");
fileInput->setValue("<>");

// Write to string with escaped characters
mx::XmlWriteOptions writeOptions;
std::string output_string = mx::writeToXmlString(doc, &writeOptions);
// Make sure there are escaped characters
REQUIRE(output_string.find("&lt;&gt;") != std::string::npos);

// Read in the document with the escaped characters and verify that the value
// is unescaped properly
mx::DocumentPtr readDoc = mx::createDocument();
readDoc->setDataLibrary(stdlib);
mx::readFromXmlString(readDoc , output_string);
imageNode = readDoc->getNode("testImage");
REQUIRE(imageNode != nullptr);
fileInput = imageNode->getInput("file");
REQUIRE(fileInput != nullptr);
std::string unescaped_string = fileInput->getValueString();
// There should not be any escaped characters in the value string
REQUIRE(unescaped_string.find("&lt;&gt;") == std::string::npos);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was always the logic as read always unescapes.

}
Loading