Changeset 66336 in webkit


Ignore:
Timestamp:
Aug 29, 2010 1:46:08 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

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):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r66335 r66336  
     12010-08-29  Pawel Hajdan  <phajdan.jr@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Fix libxml workarounds to work with recent versions of libxml.
     6        I was testing locally with libxml2-2.7.6.
     7        https://bugs.webkit.org/show_bug.cgi?id=30508
     8
     9        Based on patch by Philippe Normand <pnormand@igalia.com>.
     10
     11        This also fixes a Chromium bug:
     12        http://code.google.com/p/chromium/issues/detail?id=29333
     13
     14        * dom/XMLDocumentParserLibxml2.cpp:
     15        (WebCore::switchToUTF16):
     16        (WebCore::XMLParserContext::createStringParser):
     17        (WebCore::XMLDocumentParser::doWrite):
     18        (WebCore::startDocumentHandler):
     19
    1202010-08-29  Darin Adler  <darin@apple.com>
    221
  • trunk/WebCore/dom/XMLDocumentParserLibxml2.cpp

    r66115 r66336  
    362362};
    363363
     364static void switchToUTF16(xmlParserCtxtPtr ctxt)
     365{
     366    // Hack around libxml2's lack of encoding overide support by manually
     367    // resetting the encoding to UTF-16 before every chunk.  Otherwise libxml
     368    // will detect <?xml version="1.0" encoding="<encoding name>"?> blocks
     369    // and switch encodings, causing the parse to fail.
     370    const UChar BOM = 0xFEFF;
     371    const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
     372    xmlSwitchEncoding(ctxt, BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
     373}
     374
    364375static bool shouldAllowExternalLoad(const KURL& url)
    365376{
     
    477488    parser->_private = userData;
    478489    parser->replaceEntities = true;
    479     const UChar BOM = 0xFEFF;
    480     const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
    481     xmlSwitchEncoding(parser, BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
     490    switchToUTF16(parser);
    482491
    483492    return adoptRef(new XMLParserContext(parser));
     
    646655        RefPtr<XMLDocumentParser> protect(this);
    647656
    648         // Hack around libxml2's lack of encoding overide support by manually
    649         // resetting the encoding to UTF-16 before every chunk.  Otherwise libxml
    650         // will detect <?xml version="1.0" encoding="<encoding name>"?> blocks
    651         // and switch encodings, causing the parse to fail.
    652         const UChar BOM = 0xFEFF;
    653         const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
    654         xmlSwitchEncoding(context->context(), BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
    655 
     657        switchToUTF16(context->context());
    656658        XMLDocumentParserScope scope(document()->docLoader());
    657659        xmlParseChunk(context->context(), reinterpret_cast<const char*>(parseString.characters()), sizeof(UChar) * parseString.length(), 0);
     
    12321234{
    12331235    xmlParserCtxt* ctxt = static_cast<xmlParserCtxt*>(closure);
     1236    switchToUTF16(ctxt);
    12341237    getParser(closure)->startDocument(ctxt->version, ctxt->encoding, ctxt->standalone);
    12351238    xmlSAX2StartDocument(closure);
Note: See TracChangeset for help on using the changeset viewer.