Skip to content
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
15 changes: 14 additions & 1 deletion src/XMLDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "util/memory.h"

#include <libxml/parser.h>
#ifndef _WIN32
#include <libxml/uri.h>
#endif
#include <libxml/xmlschemas.h>
#include <libxml/c14n.h> // needs to be last to workaround old libxml2 errors

Expand Down Expand Up @@ -610,7 +613,17 @@ class XMLSchema

static Schema parser(const std::string &path)
{
auto parser = make_unique_ptr<xmlSchemaFreeParserCtxt>(xmlSchemaNewParserCtxt(path.c_str()));
#ifndef _WIN32
auto uri = make_unique_ptr(xmlURIEscapeStr(
BAD_CAST (path.starts_with('/') ? "file://" + path : path).c_str(), BAD_CAST "/:"),
[](xmlChar *value) { xmlFree(value); });
if(!uri)
THROW("Failed to construct schema URI %s", path.c_str());
const auto *schemaPath = reinterpret_cast<const char*>(uri.get());
#else
const auto *schemaPath = path.c_str();
#endif
auto parser = make_unique_ptr<xmlSchemaFreeParserCtxt>(xmlSchemaNewParserCtxt(schemaPath));
if(!parser)
THROW("Failed to create schema parser context %s", path.c_str());
xmlSchemaSetParserErrors(parser.get(), schemaValidationError, schemaValidationWarning, nullptr);
Expand Down
19 changes: 19 additions & 0 deletions test/libdigidocpp_boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,25 @@ BOOST_AUTO_TEST_CASE(WrapContainerWithExpiredSignatures)
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(XMLTestSuite)
BOOST_AUTO_TEST_CASE(SchemaPathWithSpaces)
{
struct TempSchemaDir
{
fs::path path;
~TempSchemaDir()
{
error_code ec;
fs::remove_all(path, ec);
}
} schemaDir{util::File::tempFileName().concat(" schema path")};

fs::remove(schemaDir.path);
fs::copy(DIGIDOCPPCONF, schemaDir.path, fs::copy_options::recursive);

XMLDocument doc("TSL.xml");
BOOST_CHECK_NO_THROW(XMLSchema::validate((schemaDir.path / "ts_119612v020201_201601xsd.xsd").string(), doc));
}

BOOST_AUTO_TEST_CASE(XMLBomb)
{
BOOST_CHECK_THROW(XMLDocument("xml-bomb-attr.xml"), Exception);
Expand Down
Loading