Skip to content

Commit

Permalink
fix xercesc parsing of envarionment variables in the path
Browse files Browse the repository at this point in the history
  • Loading branch information
dudarboh committed Sep 30, 2024
1 parent df37005 commit 72d1293
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions DDCore/src/XML/DocumentHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,20 @@ Document DocumentHandler::load(Handle_t base, const XMLCh* fname, UriReader* rea

/// Load XML file and parse it using URI resolver to read data.
Document DocumentHandler::load(const std::string& fname, UriReader* reader) const {
auto _clean_fname = [](const std::string& s) -> std::string {
const std::string& temp = getEnviron(s);
std::string temp2 = undressed_file_name(temp.empty() ? s : temp);
if ( strncmp(temp2.c_str(),"file:",5) == 0 ) return temp2.substr(5);
return temp2;
};
auto fname_clean = _clean_fname(fname);
std::string path;
printout(DEBUG,"DocumentHandler","+++ Loading document URI: %s",fname.c_str());
printout(DEBUG,"DocumentHandler","+++ Loading document URI: %s",fname_clean.c_str());
try {
size_t idx = fname.find(':');
size_t idq = fname.find('/');
size_t idx = fname_clean.find(':');
size_t idq = fname_clean.find('/');
if ( idq == std::string::npos ) idq = 0;
XMLURL xerurl = (const XMLCh*) Strng_t(idx==std::string::npos || idx>idq ? "file:"+fname : fname);
XMLURL xerurl = (const XMLCh*) Strng_t(idx==std::string::npos || idx>idq ? "file:"+fname_clean : fname_clean);
std::string proto = _toString(xerurl.getProtocolName());
path = _toString(xerurl.getPath());
printout(DEBUG,"DocumentHandler","+++ protocol:%s path:%s",proto.c_str(), path.c_str());
Expand All @@ -348,8 +355,8 @@ Document DocumentHandler::load(const std::string& fname, UriReader* reader) cons
if ( reader ) reader->parserLoaded(path);
}
else {
if ( reader && reader->load(fname, path) ) {
MemBufInputSource src((const XMLByte*)path.c_str(), path.length(), fname.c_str(), false);
if ( reader && reader->load(fname_clean, path) ) {
MemBufInputSource src((const XMLByte*)path.c_str(), path.length(), fname_clean.c_str(), false);
parser->parse(src);
return (XmlDocument*)parser->adoptDocument();
}
Expand All @@ -359,7 +366,7 @@ Document DocumentHandler::load(const std::string& fname, UriReader* reader) cons
catch (const std::exception& e) {
printout(ERROR,"DocumentHandler","+++ Exception(XercesC): parse(path):%s",e.what());
try {
parser->parse(fname.c_str());
parser->parse(fname_clean.c_str());
if ( reader ) reader->parserLoaded(path);
}
catch (const std::exception& ex) {
Expand Down

0 comments on commit 72d1293

Please sign in to comment.