mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fix bug 47738
Fix bug 47738 content.opf contains item in IRI format. URLDecode to decode percent-encoded characters
This commit is contained in:
@ -17,6 +17,40 @@ void CBookItem::Clear()
|
||||
m_eType = Default;
|
||||
}
|
||||
*/
|
||||
wchar_t _is_hex_char(wchar_t ch)
|
||||
{
|
||||
if(L'0' <= ch && ch <= L'9')
|
||||
return (ch - L'0');
|
||||
else if(L'A' <= ch && ch <= L'F')
|
||||
return (ch - L'A') + 10;
|
||||
else if(L'a' <= ch && ch <= L'f')
|
||||
return (ch - L'a') + 10;
|
||||
return static_cast<wchar_t>(-1);
|
||||
}
|
||||
|
||||
wchar_t _hex_str2int(wchar_t* str)
|
||||
{
|
||||
return _is_hex_char(str[0]) << 4 | _is_hex_char(str[1]);
|
||||
}
|
||||
|
||||
std::wstring URLDecode(const std::wstring& src)
|
||||
{
|
||||
std::wstring dst;
|
||||
wchar_t* buf = new wchar_t[3];
|
||||
buf[2] = L'\0';
|
||||
for(size_t i = 0; i < src.length(); i++)
|
||||
{
|
||||
if(src[i] == L'%')
|
||||
{
|
||||
buf[0] = src.at(++i);
|
||||
buf[1] = src.at(++i);
|
||||
dst.append(1, _hex_str2int(buf));
|
||||
} else
|
||||
dst.append(1, src.at(i));
|
||||
}
|
||||
delete buf;
|
||||
return dst;
|
||||
}
|
||||
|
||||
bool CBookItem::ReadItem(XmlUtils::CXmlLiteReader& oXmlLiteReader, int depth)
|
||||
{
|
||||
@ -30,12 +64,7 @@ bool CBookItem::ReadItem(XmlUtils::CXmlLiteReader& oXmlLiteReader, int depth)
|
||||
|
||||
if (sAttributeName == L"href")
|
||||
{
|
||||
size_t nPer20 = sAttributeValue.find(L"%20");
|
||||
while(nPer20 != std::wstring::npos)
|
||||
{
|
||||
sAttributeValue.replace(nPer20, 3, L" ");
|
||||
nPer20 = sAttributeValue.find(L"%20");
|
||||
}
|
||||
sAttributeValue = URLDecode(sAttributeValue);
|
||||
size_t posLastSlash = sAttributeValue.rfind(L'/');
|
||||
m_sRef = posLastSlash == std::wstring::npos ? sAttributeValue : sAttributeValue.substr(posLastSlash + 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user