1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-19 14:50:07 +03:00

parser: Fix ignorableWhitespace callback

If ignorableWhitespace differs from the "characters" callback, we have
to check for blanks as well.

Regressed with 1f5b537.
This commit is contained in:
Nick Wellnhofer 2025-03-11 14:32:35 +01:00
parent d83ff954af
commit 8696ebe182
2 changed files with 11 additions and 6 deletions

2
SAX2.c
View File

@ -2736,7 +2736,7 @@ xmlSAXVersion(xmlSAXHandler *hdlr, int version)
hdlr->reference = xmlSAX2Reference;
hdlr->characters = xmlSAX2Characters;
hdlr->cdataBlock = xmlSAX2CDataBlock;
hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
hdlr->ignorableWhitespace = xmlSAX2Characters;
hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
hdlr->comment = xmlSAX2Comment;
hdlr->warning = xmlParserWarning;

View File

@ -4779,18 +4779,23 @@ static const unsigned char test_char_data[256] = {
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 @@ xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size) {
/*
* 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;
}
}