parser: Fix ignorableWhitespace callback
If ignorableWhitespace differs from the "characters" callback, we have
to check for blanks as well.
Regressed with 1f5b537.
diff --git a/SAX2.c b/SAX2.c
index 436151e..b5c2e47 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -2736,7 +2736,7 @@
hdlr->reference = xmlSAX2Reference;
hdlr->characters = xmlSAX2Characters;
hdlr->cdataBlock = xmlSAX2CDataBlock;
- hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
+ hdlr->ignorableWhitespace = xmlSAX2Characters;
hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
hdlr->comment = xmlSAX2Comment;
hdlr->warning = xmlParserWarning;
diff --git a/parser.c b/parser.c
index 42684e0..8a26968 100644
--- a/parser.c
+++ b/parser.c
@@ -4779,18 +4779,23 @@
static void
xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size) {
+ int checkBlanks;
+
if ((ctxt->sax == NULL) || (ctxt->disableSAX))
return;
+ checkBlanks = (!ctxt->keepBlanks) ||
+ (ctxt->sax->ignorableWhitespace != ctxt->sax->characters);
+
/*
* Calling areBlanks with only parts of a text node
* is fundamentally broken, making the NOBLANKS option
* essentially unusable.
*/
- if ((!ctxt->keepBlanks) &&
- (ctxt->sax->ignorableWhitespace != ctxt->sax->characters) &&
+ if ((checkBlanks) &&
(areBlanks(ctxt, buf, size, 1))) {
- if (ctxt->sax->ignorableWhitespace != NULL)
+ if ((ctxt->sax->ignorableWhitespace != NULL) &&
+ (ctxt->keepBlanks))
ctxt->sax->ignorableWhitespace(ctxt->userData, buf, size);
} else {
if (ctxt->sax->characters != NULL)
@@ -4798,9 +4803,9 @@
/*
* The old code used to update this value for "complex" data
- * even if keepBlanks was true. This was probably a bug.
+ * even if checkBlanks was false. This was probably a bug.
*/
- if ((!ctxt->keepBlanks) && (*ctxt->space == -1))
+ if ((checkBlanks) && (*ctxt->space == -1))
*ctxt->space = -2;
}
}