fix fb2 escaping characters

This commit is contained in:
Kulikova Svetlana
2023-01-20 17:42:09 +03:00
parent ab2f79bd19
commit 276de3c7b0

View File

@ -1589,6 +1589,17 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
return S_OK;
}
void replace_all(std::wstring& s, const std::wstring& s1, const std::wstring& s2)
{
size_t pos = s.find(s1);
size_t l = s2.length();
while (pos != std::string::npos)
{
s.replace(pos, s1.length(), s2);
pos = s.find(s1, pos + l);
}
}
void readLi(NSStringUtils::CStringBuilder& oXml, NSStringUtils::CStringBuilder& oTitleInfo, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bUl, bool bWasP, bool bWasTable);
void readStream(NSStringUtils::CStringBuilder& oXml, NSStringUtils::CStringBuilder& oTitleInfo, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bWasP, bool bWasTable)
{
@ -1625,6 +1636,12 @@ void readStream(NSStringUtils::CStringBuilder& oXml, NSStringUtils::CStringBuild
if (!sAtrName.empty())
{
replace_all(sAtrContent, L"&", L"&amp;");
replace_all(sAtrContent, L"<", L"&lt;");
replace_all(sAtrContent, L">", L"&gt;");
replace_all(sAtrContent, L"\"", L"&quot;");
replace_all(sAtrContent, L"\'", L"&#39;");
if (sAtrName == L"creator")
oTitleInfo.WriteString(L"<author><nickname>" + sAtrContent + L"</nickname></author>");
else if (sAtrName == L"description")