| Index: Source/core/xml/parser/XMLDocumentParser.cpp
|
| diff --git a/Source/core/xml/parser/XMLDocumentParser.cpp b/Source/core/xml/parser/XMLDocumentParser.cpp
|
| index a86e938e650c9ee6edd53989101900dfe7ec0bcd..61b4b32af093bb837881c1f3bfdb6e98185d8dcf 100644
|
| --- a/Source/core/xml/parser/XMLDocumentParser.cpp
|
| +++ b/Source/core/xml/parser/XMLDocumentParser.cpp
|
| @@ -26,10 +26,6 @@
|
| #include "config.h"
|
| #include "core/xml/parser/XMLDocumentParser.h"
|
|
|
| -#include <libxml/catalog.h>
|
| -#include <libxml/parser.h>
|
| -#include <libxml/parserInternals.h>
|
| -#include <libxslt/xslt.h>
|
| #include "bindings/v8/ExceptionState.h"
|
| #include "bindings/v8/ExceptionStatePlaceholder.h"
|
| #include "bindings/v8/ScriptController.h"
|
| @@ -71,6 +67,10 @@
|
| #include "wtf/Threading.h"
|
| #include "wtf/Vector.h"
|
| #include "wtf/unicode/UTF8.h"
|
| +#include <libxml/catalog.h>
|
| +#include <libxml/parser.h>
|
| +#include <libxml/parserInternals.h>
|
| +#include <libxslt/xslt.h>
|
|
|
| namespace WebCore {
|
|
|
| @@ -128,13 +128,13 @@ public:
|
| , m_defaultedCount(defaultedCount)
|
| {
|
| m_namespaces = static_cast<xmlChar**>(xmlMalloc(sizeof(xmlChar*) * namespaceCount * 2));
|
| - for (int i = 0; i < namespaceCount * 2 ; i++)
|
| + for (int i = 0; i < namespaceCount * 2 ; ++i)
|
| m_namespaces[i] = xmlStrdup(namespaces[i]);
|
| m_attributes = static_cast<xmlChar**>(xmlMalloc(sizeof(xmlChar*) * attributeCount * 5));
|
| - for (int i = 0; i < attributeCount; i++) {
|
| + for (int i = 0; i < attributeCount; ++i) {
|
| // Each attribute has 5 elements in the array:
|
| // name, prefix, uri, value and an end pointer.
|
| - for (int j = 0; j < 3; j++)
|
| + for (int j = 0; j < 3; ++j)
|
| m_attributes[i * 5 + j] = xmlStrdup(attributes[i * 5 + j]);
|
| int length = attributes[i * 5 + 4] - attributes[i * 5 + 3];
|
| m_attributes[i * 5 + 3] = xmlStrndup(attributes[i * 5 + 3], length);
|
| @@ -144,11 +144,11 @@ public:
|
|
|
| virtual ~PendingStartElementNSCallback()
|
| {
|
| - for (int i = 0; i < m_namespaceCount * 2; i++)
|
| + for (int i = 0; i < m_namespaceCount * 2; ++i)
|
| xmlFree(m_namespaces[i]);
|
| xmlFree(m_namespaces);
|
| - for (int i = 0; i < m_attributeCount; i++)
|
| - for (int j = 0; j < 4; j++)
|
| + for (int i = 0; i < m_attributeCount; ++i)
|
| + for (int j = 0; j < 4; ++j)
|
| xmlFree(m_attributes[i * 5 + j]);
|
| xmlFree(m_attributes);
|
| }
|
| @@ -156,8 +156,8 @@ public:
|
| virtual void call(XMLDocumentParser* parser) OVERRIDE
|
| {
|
| parser->startElementNs(m_localName, m_prefix, m_uri,
|
| - m_namespaceCount, const_cast<const xmlChar**>(m_namespaces),
|
| - m_attributeCount, m_defaultedCount, const_cast<const xmlChar**>(m_attributes));
|
| + m_namespaceCount, const_cast<const xmlChar**>(m_namespaces),
|
| + m_attributeCount, m_defaultedCount, const_cast<const xmlChar**>(m_attributes));
|
| }
|
|
|
| private:
|
| @@ -304,7 +304,7 @@ void XMLDocumentParser::pushCurrentNode(ContainerNode* n)
|
| m_currentNodeStack.append(m_currentNode);
|
| m_currentNode = n;
|
| if (m_currentNodeStack.size() > maxXMLTreeDepth)
|
| - handleError(XMLErrors::fatal, "Excessive node nesting.", textPosition());
|
| + handleError(XMLErrors::ErrorTypeFatal, "Excessive node nesting.", textPosition());
|
| }
|
|
|
| void XMLDocumentParser::popCurrentNode()
|
| @@ -369,9 +369,9 @@ void XMLDocumentParser::append(PassRefPtr<StringImpl> inputSource)
|
| void XMLDocumentParser::handleError(XMLErrors::ErrorType type, const char* formattedMessage, TextPosition position)
|
| {
|
| m_xmlErrors.handleError(type, formattedMessage, position);
|
| - if (type != XMLErrors::warning)
|
| + if (type != XMLErrors::ErrorTypeWarning)
|
| m_sawError = true;
|
| - if (type == XMLErrors::fatal)
|
| + if (type == XMLErrors::ErrorTypeFatal)
|
| stopParsing();
|
| }
|
|
|
| @@ -419,9 +419,9 @@ void XMLDocumentParser::end()
|
| if (m_parserPaused)
|
| return;
|
|
|
| - if (m_sawError)
|
| + if (m_sawError) {
|
| insertErrorMessageBlock();
|
| - else {
|
| + } else {
|
| exitText();
|
| document()->styleResolverChanged();
|
| }
|
| @@ -467,12 +467,13 @@ void XMLDocumentParser::notifyFinished(Resource* unusedResource)
|
| ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e.get());
|
| ASSERT(scriptLoader);
|
|
|
| - // JavaScript can detach this parser, make sure it's kept alive even if detached.
|
| + // JavaScript can detach this parser, make sure it's kept alive even if
|
| + // detached.
|
| RefPtrWillBeRawPtr<XMLDocumentParser> protect(this);
|
|
|
| - if (errorOccurred)
|
| + if (errorOccurred) {
|
| scriptLoader->dispatchErrorEvent();
|
| - else if (!wasCanceled) {
|
| + } else if (!wasCanceled) {
|
| scriptLoader->executeScript(sourceCode);
|
| scriptLoader->dispatchLoadEvent();
|
| }
|
| @@ -490,10 +491,8 @@ bool XMLDocumentParser::isWaitingForScripts() const
|
|
|
| void XMLDocumentParser::pauseParsing()
|
| {
|
| - if (m_parsingFragment)
|
| - return;
|
| -
|
| - m_parserPaused = true;
|
| + if (!m_parsingFragment)
|
| + m_parserPaused = true;
|
| }
|
|
|
| bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy)
|
| @@ -511,10 +510,14 @@ bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragm
|
|
|
| RefPtrWillBeRawPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, contextElement, parserContentPolicy);
|
| bool wellFormed = parser->appendFragmentSource(chunk);
|
| - // Do not call finish(). Current finish() and doEnd() implementations touch the main Document/loader
|
| - // and can cause crashes in the fragment case.
|
| - parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction.
|
| - return wellFormed; // appendFragmentSource()'s wellFormed is more permissive than wellFormed().
|
| +
|
| + // Do not call finish(). Current finish() and doEnd() implementations touch
|
| + // the main Document/loader and can cause crashes in the fragment case.
|
| +
|
| + // Allows ~DocumentParser to assert it was detached before destruction.
|
| + parser->detach();
|
| + // appendFragmentSource()'s wellFormed is more permissive than wellFormed().
|
| + return wellFormed;
|
| }
|
|
|
| static int globalDescriptor = 0;
|
| @@ -522,8 +525,9 @@ static ThreadIdentifier libxmlLoaderThread = 0;
|
|
|
| static int matchFunc(const char*)
|
| {
|
| - // Only match loads initiated due to uses of libxml2 from within XMLDocumentParser to avoid
|
| - // interfering with client applications that also use libxml2. http://bugs.webkit.org/show_bug.cgi?id=17353
|
| + // Only match loads initiated due to uses of libxml2 from within
|
| + // XMLDocumentParser to avoid interfering with client applications that also
|
| + // use libxml2. http://bugs.webkit.org/show_bug.cgi?id=17353
|
| return XMLDocumentParserScope::currentFetcher && currentThread() == libxmlLoaderThread;
|
| }
|
|
|
| @@ -537,9 +541,9 @@ static inline void setAttributes(Element* element, Vector<Attribute>& attributeV
|
| static void switchEncoding(xmlParserCtxtPtr ctxt, bool is8Bit)
|
| {
|
| // 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.
|
| + // 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.
|
| if (is8Bit) {
|
| xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1);
|
| return;
|
| @@ -589,8 +593,8 @@ static bool shouldAllowExternalLoad(const KURL& url)
|
| if (isLibxmlDefaultCatalogFile(url))
|
| return false;
|
|
|
| - // The most common DTD. There isn't much point in hammering www.w3c.org
|
| - // by requesting this URL for every XHTML document.
|
| + // The most common DTD. There isn't much point in hammering www.w3c.org by
|
| + // requesting this URL for every XHTML document.
|
| if (urlString.startsWith("http://www.w3.org/TR/xhtml", false))
|
| return false;
|
|
|
| @@ -598,12 +602,12 @@ static bool shouldAllowExternalLoad(const KURL& url)
|
| if (urlString.startsWith("http://www.w3.org/Graphics/SVG", false))
|
| return false;
|
|
|
| - // The libxml doesn't give us a lot of context for deciding whether to
|
| - // allow this request. In the worst case, this load could be for an
|
| - // external entity and the resulting document could simply read the
|
| - // retrieved content. If we had more context, we could potentially allow
|
| - // the parser to load a DTD. As things stand, we take the conservative
|
| - // route and allow same-origin requests only.
|
| + // The libxml doesn't give us a lot of context for deciding whether to allow
|
| + // this request. In the worst case, this load could be for an external
|
| + // entity and the resulting document could simply read the retrieved
|
| + // content. If we had more context, we could potentially allow the parser to
|
| + // load a DTD. As things stand, we take the conservative route and allow
|
| + // same-origin requests only.
|
| if (!XMLDocumentParserScope::currentFetcher->document()->securityOrigin()->canRequest(url)) {
|
| XMLDocumentParserScope::currentFetcher->printAccessDeniedMessage(url);
|
| return false;
|
| @@ -864,7 +868,8 @@ void XMLDocumentParser::doWrite(const String& parseString)
|
| // Protect the libxml context from deletion during a callback
|
| RefPtr<XMLParserContext> context = m_context;
|
|
|
| - // libXML throws an error if you try to switch the encoding for an empty string.
|
| + // libXML throws an error if you try to switch the encoding for an empty
|
| + // string.
|
| if (parseString.length()) {
|
| // JavaScript may cause the parser to detach during parseChunk
|
| // keep this alive until this function is done.
|
| @@ -880,24 +885,24 @@ void XMLDocumentParser::doWrite(const String& parseString)
|
| return;
|
| }
|
|
|
| - // FIXME: Why is this here? And why is it after we process the passed source?
|
| + // FIXME: Why is this here? And why is it after we process the passed
|
| + // source?
|
| if (document()->sawDecodingError()) {
|
| // If the decoder saw an error, report it as fatal (stops parsing)
|
| TextPosition position(OrdinalNumber::fromOneBasedInt(context->context()->input->line), OrdinalNumber::fromOneBasedInt(context->context()->input->col));
|
| - handleError(XMLErrors::fatal, "Encoding error", position);
|
| + handleError(XMLErrors::ErrorTypeFatal, "Encoding error", position);
|
| }
|
| }
|
|
|
| -struct _xmlSAX2Namespace {
|
| +struct xmlSAX2Namespace {
|
| const xmlChar* prefix;
|
| const xmlChar* uri;
|
| };
|
| -typedef struct _xmlSAX2Namespace xmlSAX2Namespace;
|
|
|
| static inline void handleNamespaceAttributes(Vector<Attribute>& prefixedAttributes, const xmlChar** libxmlNamespaces, int nbNamespaces, ExceptionState& exceptionState)
|
| {
|
| xmlSAX2Namespace* namespaces = reinterpret_cast<xmlSAX2Namespace*>(libxmlNamespaces);
|
| - for (int i = 0; i < nbNamespaces; i++) {
|
| + for (int i = 0; i < nbNamespaces; ++i) {
|
| AtomicString namespaceQName = xmlnsAtom;
|
| AtomicString namespaceURI = toAtomicString(namespaces[i].uri);
|
| if (namespaces[i].prefix)
|
| @@ -911,19 +916,18 @@ static inline void handleNamespaceAttributes(Vector<Attribute>& prefixedAttribut
|
| }
|
| }
|
|
|
| -struct _xmlSAX2Attributes {
|
| +struct xmlSAX2Attributes {
|
| const xmlChar* localname;
|
| const xmlChar* prefix;
|
| const xmlChar* uri;
|
| const xmlChar* value;
|
| const xmlChar* end;
|
| };
|
| -typedef struct _xmlSAX2Attributes xmlSAX2Attributes;
|
|
|
| static inline void handleElementAttributes(Vector<Attribute>& prefixedAttributes, const xmlChar** libxmlAttributes, int nbAttributes, ExceptionState& exceptionState)
|
| {
|
| xmlSAX2Attributes* attributes = reinterpret_cast<xmlSAX2Attributes*>(libxmlAttributes);
|
| - for (int i = 0; i < nbAttributes; i++) {
|
| + for (int i = 0; i < nbAttributes; ++i) {
|
| int valueLength = static_cast<int>(attributes[i].end - attributes[i].value);
|
| AtomicString attrValue = toAtomicString(attributes[i].value, valueLength);
|
| String attrPrefix = toString(attributes[i].prefix);
|
| @@ -1016,8 +1020,8 @@ void XMLDocumentParser::endElementNs()
|
| return;
|
| }
|
|
|
| - // JavaScript can detach the parser. Make sure this is not released
|
| - // before the end of this method.
|
| + // JavaScript can detach the parser. Make sure this is not released before
|
| + // the end of this method.
|
| RefPtrWillBeRawPtr<XMLDocumentParser> protect(this);
|
|
|
| exitText();
|
| @@ -1067,7 +1071,8 @@ void XMLDocumentParser::endElementNs()
|
| m_scriptElement = element;
|
| m_pendingScript->addClient(this);
|
|
|
| - // m_pendingScript will be 0 if script was already loaded and addClient() executed it.
|
| + // m_pendingScript will be 0 if script was already loaded and
|
| + // addClient() executed it.
|
| if (m_pendingScript)
|
| pauseParsing();
|
| } else {
|
| @@ -1119,7 +1124,7 @@ void XMLDocumentParser::processingInstruction(const String& target, const String
|
| return;
|
|
|
| if (m_parserPaused) {
|
| - m_pendingCallbacks.append(adoptPtr(new PendingProcessingInstructionCallback(target ,data)));
|
| + m_pendingCallbacks.append(adoptPtr(new PendingProcessingInstructionCallback(target, data)));
|
| return;
|
| }
|
|
|
| @@ -1145,10 +1150,11 @@ void XMLDocumentParser::processingInstruction(const String& target, const String
|
|
|
| m_sawXSLTransform = !m_sawFirstElement && pi->isXSL();
|
| if (m_sawXSLTransform && !document()->transformSourceDocument()) {
|
| - // This behavior is very tricky. We call stopParsing() here because we want to stop processing the document
|
| - // until we're ready to apply the transform, but we actually still want to be fed decoded string pieces to
|
| - // accumulate in m_originalSourceForTransform. So, we call stopParsing() here and
|
| - // check isStopped() in element callbacks.
|
| + // This behavior is very tricky. We call stopParsing() here because we
|
| + // want to stop processing the document until we're ready to apply the
|
| + // transform, but we actually still want to be fed decoded string pieces
|
| + // to accumulate in m_originalSourceForTransform. So, we call
|
| + // stopParsing() here and check isStopped() in element callbacks.
|
| // FIXME: This contradicts the contract of DocumentParser.
|
| stopParsing();
|
| }
|
| @@ -1193,7 +1199,7 @@ enum StandaloneInfo {
|
|
|
| void XMLDocumentParser::startDocument(const String& version, const String& encoding, int standalone)
|
| {
|
| - StandaloneInfo standaloneInfo = (StandaloneInfo)standalone;
|
| + StandaloneInfo standaloneInfo = static_cast<StandaloneInfo>(standalone);
|
| if (standaloneInfo == NoXMlDeclaration) {
|
| document()->setHasXMLDeclaration(false);
|
| return;
|
| @@ -1268,7 +1274,7 @@ static void warningHandler(void* closure, const char* message, ...)
|
| {
|
| va_list args;
|
| va_start(args, message);
|
| - getParser(closure)->error(XMLErrors::warning, message, args);
|
| + getParser(closure)->error(XMLErrors::ErrorTypeWarning, message, args);
|
| va_end(args);
|
| }
|
|
|
| @@ -1277,7 +1283,7 @@ static void fatalErrorHandler(void* closure, const char* message, ...)
|
| {
|
| va_list args;
|
| va_start(args, message);
|
| - getParser(closure)->error(XMLErrors::fatal, message, args);
|
| + getParser(closure)->error(XMLErrors::ErrorTypeFatal, message, args);
|
| va_end(args);
|
| }
|
|
|
| @@ -1286,12 +1292,12 @@ static void normalErrorHandler(void* closure, const char* message, ...)
|
| {
|
| va_list args;
|
| va_start(args, message);
|
| - getParser(closure)->error(XMLErrors::nonFatal, message, args);
|
| + getParser(closure)->error(XMLErrors::ErrorTypeNonFatal, message, args);
|
| va_end(args);
|
| }
|
|
|
| -// Using a static entity and marking it XML_INTERNAL_PREDEFINED_ENTITY is
|
| -// a hack to avoid malloc/free. Using a global variable like this could cause trouble
|
| +// Using a static entity and marking it XML_INTERNAL_PREDEFINED_ENTITY is a hack
|
| +// to avoid malloc/free. Using a global variable like this could cause trouble
|
| // if libxml implementation details were to change
|
| static xmlChar sharedXHTMLEntityResult[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
| @@ -1383,22 +1389,24 @@ static void internalSubsetHandler(void* closure, const xmlChar* name, const xmlC
|
| static void externalSubsetHandler(void* closure, const xmlChar*, const xmlChar* externalId, const xmlChar*)
|
| {
|
| String extId = toString(externalId);
|
| - if ((extId == "-//W3C//DTD XHTML 1.0 Transitional//EN")
|
| - || (extId == "-//W3C//DTD XHTML 1.1//EN")
|
| - || (extId == "-//W3C//DTD XHTML 1.0 Strict//EN")
|
| - || (extId == "-//W3C//DTD XHTML 1.0 Frameset//EN")
|
| - || (extId == "-//W3C//DTD XHTML Basic 1.0//EN")
|
| - || (extId == "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN")
|
| - || (extId == "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN")
|
| - || (extId == "-//WAPFORUM//DTD XHTML Mobile 1.0//EN")
|
| - || (extId == "-//WAPFORUM//DTD XHTML Mobile 1.1//EN")
|
| - || (extId == "-//WAPFORUM//DTD XHTML Mobile 1.2//EN"))
|
| - getParser(closure)->setIsXHTMLDocument(true); // controls if we replace entities or not.
|
| + if (extId == "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
| + || extId == "-//W3C//DTD XHTML 1.1//EN"
|
| + || extId == "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| + || extId == "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
| + || extId == "-//W3C//DTD XHTML Basic 1.0//EN"
|
| + || extId == "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
|
| + || extId == "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
|
| + || extId == "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
|
| + || extId == "-//WAPFORUM//DTD XHTML Mobile 1.1//EN"
|
| + || extId == "-//WAPFORUM//DTD XHTML Mobile 1.2//EN") {
|
| + // Controls if we replace entities or not.
|
| + getParser(closure)->setIsXHTMLDocument(true);
|
| + }
|
| }
|
|
|
| static void ignorableWhitespaceHandler(void*, const xmlChar*, int)
|
| {
|
| - // nothing to do, but we need this to work around a crasher
|
| + // Nothing to do, but we need this to work around a crasher.
|
| // http://bugzilla.gnome.org/show_bug.cgi?id=172255
|
| // http://bugs.webkit.org/show_bug.cgi?id=5792
|
| }
|
| @@ -1432,9 +1440,9 @@ void XMLDocumentParser::initializeParserContext(const CString& chunk)
|
| m_sawFirstElement = false;
|
|
|
| XMLDocumentParserScope scope(document()->fetcher());
|
| - if (m_parsingFragment)
|
| + if (m_parsingFragment) {
|
| m_context = XMLParserContext::createMemoryParser(&sax, this, chunk);
|
| - else {
|
| + } else {
|
| ASSERT(!chunk.data());
|
| m_context = XMLParserContext::createStringParser(&sax, this);
|
| }
|
| @@ -1461,12 +1469,12 @@ void XMLDocumentParser::doEnd()
|
| } else if (m_sawXSLTransform) {
|
| xmlDocPtr doc = xmlDocPtrForString(document()->fetcher(), m_originalSourceForTransform.toString(), document()->url().string());
|
| document()->setTransformSource(adoptPtr(new TransformSource(doc)));
|
| -
|
| - document()->setParsing(false); // Make the document think it's done, so it will apply XSL stylesheets.
|
| + // Make the document think it's done, so it will apply XSL stylesheets.
|
| + document()->setParsing(false);
|
| document()->styleResolverChanged();
|
|
|
| - // styleResolverChanged() call can detach the parser and null out its document.
|
| - // In that case, we just bail out.
|
| + // styleResolverChanged() call can detach the parser and null out its
|
| + // document. In that case, we just bail out.
|
| if (isDetached())
|
| return;
|
|
|
| @@ -1480,8 +1488,8 @@ xmlDocPtr xmlDocPtrForString(ResourceFetcher* fetcher, const String& source, con
|
| if (source.isEmpty())
|
| return 0;
|
| // Parse in a single chunk into an xmlDocPtr
|
| - // FIXME: Hook up error handlers so that a failure to parse the main document results in
|
| - // good error messages.
|
| + // FIXME: Hook up error handlers so that a failure to parse the main
|
| + // document results in good error messages.
|
| XMLDocumentParserScope scope(fetcher, errorFunc, 0);
|
| XMLParserInput input(source);
|
| return xmlReadMemory(input.data(), input.size(), url.latin1().data(), input.encoding(), XSLT_PARSE_OPTIONS);
|
| @@ -1502,8 +1510,7 @@ TextPosition XMLDocumentParser::textPosition() const
|
| xmlParserCtxtPtr context = this->context();
|
| if (!context)
|
| return TextPosition::minimumPosition();
|
| - return TextPosition(OrdinalNumber::fromOneBasedInt(context->input->line),
|
| - OrdinalNumber::fromOneBasedInt(context->input->col));
|
| + return TextPosition(OrdinalNumber::fromOneBasedInt(context->input->line), OrdinalNumber::fromOneBasedInt(context->input->col));
|
| }
|
|
|
| void XMLDocumentParser::stopParsing()
|
| @@ -1551,7 +1558,8 @@ bool XMLDocumentParser::appendFragmentSource(const String& chunk)
|
|
|
| CString chunkAsUtf8 = chunk.utf8();
|
|
|
| - // libxml2 takes an int for a length, and therefore can't handle XML chunks larger than 2 GiB.
|
| + // libxml2 takes an int for a length, and therefore can't handle XML chunks
|
| + // larger than 2 GiB.
|
| if (chunkAsUtf8.length() > INT_MAX)
|
| return false;
|
|
|
| @@ -1559,13 +1567,16 @@ bool XMLDocumentParser::appendFragmentSource(const String& chunk)
|
| xmlParseContent(context());
|
| endDocument(); // Close any open text nodes.
|
|
|
| - // FIXME: If this code is actually needed, it should probably move to finish()
|
| - // XMLDocumentParserQt has a similar check (m_stream.error() == QXmlStreamReader::PrematureEndOfDocumentError) in doEnd().
|
| - // Check if all the chunk has been processed.
|
| + // FIXME: If this code is actually needed, it should probably move to
|
| + // finish()
|
| + // XMLDocumentParserQt has a similar check (m_stream.error() ==
|
| + // QXmlStreamReader::PrematureEndOfDocumentError) in doEnd(). Check if all
|
| + // the chunk has been processed.
|
| long bytesProcessed = xmlByteConsumed(context());
|
| - if (bytesProcessed == -1 || ((unsigned long)bytesProcessed) != chunkAsUtf8.length()) {
|
| - // FIXME: I don't believe we can hit this case without also having seen an error or a null byte.
|
| - // If we hit this ASSERT, we've found a test case which demonstrates the need for this code.
|
| + if (bytesProcessed == -1 || static_cast<unsigned long>(bytesProcessed) != chunkAsUtf8.length()) {
|
| + // FIXME: I don't believe we can hit this case without also having seen
|
| + // an error or a null byte. If we hit this ASSERT, we've found a test
|
| + // case which demonstrates the need for this code.
|
| ASSERT(m_sawError || (bytesProcessed >= 0 && !chunkAsUtf8.data()[bytesProcessed]));
|
| return false;
|
| }
|
| @@ -1594,7 +1605,7 @@ static void attributesStartElementNsHandler(void* closure, const xmlChar* xmlLoc
|
| state->gotAttributes = true;
|
|
|
| xmlSAX2Attributes* attributes = reinterpret_cast<xmlSAX2Attributes*>(libxmlAttributes);
|
| - for (int i = 0; i < nbAttributes; i++) {
|
| + for (int i = 0; i < nbAttributes; ++i) {
|
| String attrLocalName = toString(attributes[i].localname);
|
| int valueLength = (int) (attributes[i].end - attributes[i].value);
|
| String attrValue = toString(attributes[i].value, valueLength);
|
|
|