diff --git a/src/colorer/utils/Environment.cpp b/src/colorer/utils/Environment.cpp index 5fb09f6..de90164 100644 --- a/src/colorer/utils/Environment.cpp +++ b/src/colorer/utils/Environment.cpp @@ -1,10 +1,10 @@ #include "colorer/utils/Environment.h" +#include #ifdef WIN32 #include #include -#else -#include #endif + namespace colorer { fs::path Environment::to_filepath(const UnicodeString* str) { @@ -159,4 +159,23 @@ UnicodeString Environment::getAbsolutePath(const UnicodeString& basePath, const newPath.append(relPath); return newPath; } + +UnicodeString Environment::expandSpecialEnvironment(const UnicodeString& path) +{ + COLORER_LOG_DEBUG("expand system environment for '%'", path); + std::smatch matcher; + std::string result; + auto text = UStr::to_stdstr(&path); + static const std::regex env_re {R"--(\$([[:alpha:]]\w*)\b)--"}; + while (std::regex_search(text, matcher, env_re)) { + result += matcher.prefix().str(); + auto a = getOSVariable(matcher[1].str().c_str()); + result += UStr::to_stdstr(a); + text = matcher.suffix().str(); + } + result += text; + + COLORER_LOG_DEBUG("result of expand '%'", result); + return UnicodeString(result.c_str()); +} } // namespace colorer \ No newline at end of file diff --git a/src/colorer/utils/Environment.h b/src/colorer/utils/Environment.h index ded7972..74de02e 100644 --- a/src/colorer/utils/Environment.h +++ b/src/colorer/utils/Environment.h @@ -26,6 +26,8 @@ class Environment const UnicodeString& extension); static bool isRegularFile(const UnicodeString* basePath, const UnicodeString* relPath, UnicodeString& fullPath); static UnicodeString getAbsolutePath(const UnicodeString& basePath, const UnicodeString& relPath); + + static UnicodeString expandSpecialEnvironment(const UnicodeString& path); }; } // namespace colorer diff --git a/src/colorer/xml/libxml2/LibXmlReader.cpp b/src/colorer/xml/libxml2/LibXmlReader.cpp index d8e6497..4367784 100644 --- a/src/colorer/xml/libxml2/LibXmlReader.cpp +++ b/src/colorer/xml/libxml2/LibXmlReader.cpp @@ -141,10 +141,17 @@ xmlParserInputPtr LibXmlReader::xmlMyExternalEntityLoader(const char* URL, const // путем склейки пути от текущего файла и указанного в external entity. // При этом в параметрах функции или в контексте нет ни пути до исходного файла, ни до файла в entity - const UnicodeString string_url(URL); + UnicodeString string_url(URL); + if (!is_full_path && string_url.startsWith(u"env:")) { + const auto exp = colorer::Environment::expandSpecialEnvironment(string_url); + string_url = UnicodeString(exp, 4); + } #ifdef COLORER_FEATURE_ZIPINPUTSOURCE if (string_url.startsWith(jar) || current_file->startsWith(jar)) { + if (!is_full_path) { + string_url = colorer::Environment::expandSpecialEnvironment(string_url); + } auto paths = LibXmlInputSource::getFullPathFromPathJar(string_url, is_full_path ? nullptr : current_file.get()); is_full_path = false; xmlParserInputPtr ret = nullptr; @@ -156,7 +163,7 @@ xmlParserInputPtr LibXmlReader::xmlMyExternalEntityLoader(const char* URL, const } #endif is_full_path = false; - xmlParserInputPtr ret = xmlNewInputFromFile(ctxt, URL); + xmlParserInputPtr ret = xmlNewInputFromFile(ctxt, UStr::to_stdstr(&string_url).c_str()); return ret; }