2010-08-29 Pawel Hajdan <phajdan.jr@chromium.org>

        Reviewed by Darin Adler.

        Fix libxml workarounds to work with recent versions of libxml.
        I was testing locally with libxml2-2.7.6.
        https://bugs.webkit.org/show_bug.cgi?id=30508

        Based on patch by Philippe Normand <pnormand@igalia.com>.

        This also fixes a Chromium bug:
        http://code.google.com/p/chromium/issues/detail?id=29333

        * dom/XMLDocumentParserLibxml2.cpp:
        (WebCore::switchToUTF16):
        (WebCore::XMLParserContext::createStringParser):
        (WebCore::XMLDocumentParser::doWrite):
        (WebCore::startDocumentHandler):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66336 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5355861b
2010-08-29 Pawel Hajdan <phajdan.jr@chromium.org>
Reviewed by Darin Adler.
Fix libxml workarounds to work with recent versions of libxml.
I was testing locally with libxml2-2.7.6.
https://bugs.webkit.org/show_bug.cgi?id=30508
Based on patch by Philippe Normand <pnormand@igalia.com>.
This also fixes a Chromium bug:
http://code.google.com/p/chromium/issues/detail?id=29333
* dom/XMLDocumentParserLibxml2.cpp:
(WebCore::switchToUTF16):
(WebCore::XMLParserContext::createStringParser):
(WebCore::XMLDocumentParser::doWrite):
(WebCore::startDocumentHandler):
2010-08-29 Darin Adler <darin@apple.com>
Try to fix Windows build.
......@@ -361,6 +361,17 @@ private:
unsigned m_currentOffset;
};
static void switchToUTF16(xmlParserCtxtPtr ctxt)
{
// Hack around libxml2's lack of encoding overide support by manually
// resetting the encoding to UTF-16 before every chunk. Otherwise libxml
// will detect <?xml version="1.0" encoding="<encoding name>"?> blocks
// and switch encodings, causing the parse to fail.
const UChar BOM = 0xFEFF;
const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
xmlSwitchEncoding(ctxt, BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
}
static bool shouldAllowExternalLoad(const KURL& url)
{
String urlString = url.string();
......@@ -476,9 +487,7 @@ PassRefPtr<XMLParserContext> XMLParserContext::createStringParser(xmlSAXHandlerP
xmlParserCtxtPtr parser = xmlCreatePushParserCtxt(handlers, 0, 0, 0, 0);
parser->_private = userData;
parser->replaceEntities = true;
const UChar BOM = 0xFEFF;
const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
xmlSwitchEncoding(parser, BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
switchToUTF16(parser);
return adoptRef(new XMLParserContext(parser));
}
......@@ -645,14 +654,7 @@ void XMLDocumentParser::doWrite(const String& parseString)
// keep this alive until this function is done.
RefPtr<XMLDocumentParser> protect(this);
// Hack around libxml2's lack of encoding overide support by manually
// resetting the encoding to UTF-16 before every chunk. Otherwise libxml
// will detect <?xml version="1.0" encoding="<encoding name>"?> blocks
// and switch encodings, causing the parse to fail.
const UChar BOM = 0xFEFF;
const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
xmlSwitchEncoding(context->context(), BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
switchToUTF16(context->context());
XMLDocumentParserScope scope(document()->docLoader());
xmlParseChunk(context->context(), reinterpret_cast<const char*>(parseString.characters()), sizeof(UChar) * parseString.length(), 0);
......@@ -1231,6 +1233,7 @@ static xmlEntityPtr getEntityHandler(void* closure, const xmlChar* name)
static void startDocumentHandler(void* closure)
{
xmlParserCtxt* ctxt = static_cast<xmlParserCtxt*>(closure);
switchToUTF16(ctxt);
getParser(closure)->startDocument(ctxt->version, ctxt->encoding, ctxt->standalone);
xmlSAX2StartDocument(closure);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment