View Single Post
Old 02-21-2016, 05:30 PM   #5
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,544
Karma: 5703586
Join Date: Nov 2009
Device: many
Yes, definite bug in Sigil code here. It looks like a really old one as well.

This regular expression to fix xml declarations in ImportEPUB.cpp is not properly restricted and it is causing the problem:

Code:
.//Misc/HTMLEncodingResolver.cpp:const QString VERSION_ATTRIBUTE    = "version\\s*=\\s*(?:\"|')([^\"']+)(?:\"|')";

.//BookManipulation/XhtmlDoc.cpp:const int XML_DECLARATION_SEARCH_PREFIX_SIZE = 150;


QString ImportEPUB::PrepareOPFForReading(const QString &source)
{
    QString source_copy(source);
    QString prefix = source_copy.left(XML_DECLARATION_SEARCH_PREFIX_SIZE);
    QRegularExpression version(VERSION_ATTRIBUTE);
    QRegularExpressionMatch mo = version.match(prefix);
    // MASSIVE hack for XML 1.1 "support";                                                                                      
    // this is only for people who specify                                                                                      
    // XML 1.1 when they actually only use XML 1.0                                                                              
    source_copy.replace(mo.capturedStart(), mo.capturedLength(), "version=\"1.0\"");
    return source_copy;
}
This bug will hit any content.opf file that does not start with a proper xml declaration. This bug has been in Sigil for a long time. The package version tag did not matter much in earlier versions of Sigil but it does now since we need it to properly detect epub 3 from epub 2.

I will look into fixing this by restricting it to the xml declaration.

Thanks for the bug report!

KevinH

Last edited by KevinH; 02-21-2016 at 08:51 PM.
KevinH is offline   Reply With Quote