Merge pull request #3224 from jolavillette/FeedReader/FixWindowsMSYS2XmlTextExtractionTruncation

Fix FeedReader text truncation on Windows MSYS2 by forcing UTF-8 and improving XML extraction
This commit is contained in:
csoler 2026-06-02 14:41:26 +02:00 committed by GitHub
commit bd58953ca2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 38 deletions

View File

@ -32,7 +32,7 @@ bool HTMLWrapper::readHTML(const char *html, const char *url)
cleanup();
handleError(true, mLastErrorString);
mDocument = htmlReadMemory(html, strlen(html), url, "", /*HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | */HTML_PARSE_COMPACT | HTML_PARSE_NONET | HTML_PARSE_NOBLANKS);
mDocument = htmlReadMemory(html, strlen(html), url, "UTF-8", /*HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | */HTML_PARSE_COMPACT | HTML_PARSE_NONET | HTML_PARSE_NOBLANKS);
handleError(false, mLastErrorString);
if (mDocument) {

View File

@ -124,42 +124,24 @@ void XMLWrapper::attach(xmlDocPtr document)
bool XMLWrapper::convertToString(const xmlChar *xmlText, std::string &text)
{
bool result = false;
xmlBufferPtr in = xmlBufferCreateStatic((void*) xmlText, xmlStrlen(xmlText));
xmlBufferPtr out = xmlBufferCreate();
int ret = xmlCharEncOutFunc(mCharEncodingHandler, out, in);
if (ret >= 0) {
result = true;
text = (char*) xmlBufferContent(out);
if (!xmlText) {
text.clear();
return false;
}
xmlBufferFree(in);
xmlBufferFree(out);
return result;
text = (const char*) xmlText;
return true;
}
bool XMLWrapper::convertFromString(const char *text, xmlChar *&xmlText)
{
bool result = false;
xmlBufferPtr in = xmlBufferCreateStatic((void*) text, strlen(text));
xmlBufferPtr out = xmlBufferCreate();
int ret = xmlCharEncInFunc(mCharEncodingHandler, out, in);
if (ret >= 0) {
result = true;
#if LIBXML_VERSION >= 20800
xmlText = xmlBufferDetach(out);
#else
xmlText = xmlStrdup(xmlBufferContent(out));
#endif
if (!text) {
xmlText = NULL;
return false;
}
xmlBufferFree(in);
xmlBufferFree(out);
return result;
xmlText = xmlStrdup(BAD_CAST text);
return xmlText != NULL;
}
xmlDocPtr XMLWrapper::getDocument() const
@ -345,15 +327,7 @@ bool XMLWrapper::getChildText(xmlNodePtr node, const char *childName, std::strin
return nodeDump(div, text, true);
}
if (child->children->type != XML_TEXT_NODE) {
return false;
}
if (child->children->content) {
return convertToString(child->children->content, text);
}
return true;
return getContent(child, text, false);
}
std::string XMLWrapper::getAttr(xmlNodePtr node, xmlAttrPtr attr)