Skip to content

Commit aa8c56b

Browse files
committed
parser: Fix XML_PARSE_NOBLANKS dropping non-whitespace text
Regressed with 1f5b537. Fixes #884.
1 parent b1c3fe0 commit aa8c56b

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

parser.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4778,7 +4778,8 @@ static const unsigned char test_char_data[256] = {
47784778
};
47794779

47804780
static void
4781-
xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size) {
4781+
xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size,
4782+
int isBlank) {
47824783
int checkBlanks;
47834784

47844785
if ((ctxt->sax == NULL) || (ctxt->disableSAX))
@@ -4793,7 +4794,7 @@ xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size) {
47934794
* essentially unusable.
47944795
*/
47954796
if ((checkBlanks) &&
4796-
(areBlanks(ctxt, buf, size, 1))) {
4797+
(areBlanks(ctxt, buf, size, isBlank))) {
47974798
if ((ctxt->sax->ignorableWhitespace != NULL) &&
47984799
(ctxt->keepBlanks))
47994800
ctxt->sax->ignorableWhitespace(ctxt->userData, buf, size);
@@ -4855,7 +4856,7 @@ xmlParseCharDataInternal(xmlParserCtxtPtr ctxt, int partial) {
48554856
const xmlChar *tmp = ctxt->input->cur;
48564857
ctxt->input->cur = in;
48574858

4858-
xmlCharacters(ctxt, tmp, nbchar);
4859+
xmlCharacters(ctxt, tmp, nbchar, 1);
48594860
}
48604861
return;
48614862
}
@@ -4891,7 +4892,7 @@ xmlParseCharDataInternal(xmlParserCtxtPtr ctxt, int partial) {
48914892
const xmlChar *tmp = ctxt->input->cur;
48924893
ctxt->input->cur = in;
48934894

4894-
xmlCharacters(ctxt, tmp, nbchar);
4895+
xmlCharacters(ctxt, tmp, nbchar, 0);
48954896

48964897
line = ctxt->input->line;
48974898
col = ctxt->input->col;
@@ -4958,7 +4959,7 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int partial) {
49584959
if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) {
49594960
buf[nbchar] = 0;
49604961

4961-
xmlCharacters(ctxt, buf, nbchar);
4962+
xmlCharacters(ctxt, buf, nbchar, 0);
49624963
nbchar = 0;
49634964
SHRINK;
49644965
}
@@ -4967,7 +4968,7 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int partial) {
49674968
if (nbchar != 0) {
49684969
buf[nbchar] = 0;
49694970

4970-
xmlCharacters(ctxt, buf, nbchar);
4971+
xmlCharacters(ctxt, buf, nbchar, 0);
49714972
}
49724973
/*
49734974
* cur == 0 can mean

testparser.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,39 @@ testCtxtParseContent(void) {
255255

256256
return err;
257257
}
258+
259+
static int
260+
testNoBlanks(void) {
261+
const xmlChar xml[] =
262+
"<refentry>\n"
263+
" <refsect1>\n"
264+
" <para>\n"
265+
" Run <command>tester --help</command> for more options.\n"
266+
" </para>\n"
267+
" </refsect1>\n"
268+
"</refentry>\n";
269+
const xmlChar expect[] =
270+
"<?xml version=\"1.0\"?>\n"
271+
"<refentry><refsect1><para>\n"
272+
" Run <command>tester --help</command> for more options.\n"
273+
" </para></refsect1></refentry>\n";
274+
xmlDocPtr doc;
275+
xmlChar *out;
276+
int size;
277+
int err = 0;
278+
279+
doc = xmlReadDoc(xml, NULL, NULL, XML_PARSE_NOBLANKS);
280+
xmlDocDumpMemory(doc, &out, &size);
281+
xmlFreeDoc(doc);
282+
283+
if (!xmlStrEqual(out, expect)) {
284+
fprintf(stderr, "parsing with XML_PARSE_NOBLANKS failed\n");
285+
err = 1;
286+
}
287+
xmlFree(out);
288+
289+
return err;
290+
}
258291
#endif /* LIBXML_OUTPUT_ENABLED */
259292

260293
#ifdef LIBXML_SAX1_ENABLED
@@ -1123,6 +1156,7 @@ main(void) {
11231156
#endif
11241157
#ifdef LIBXML_OUTPUT_ENABLED
11251158
err |= testCtxtParseContent();
1159+
err |= testNoBlanks();
11261160
#endif
11271161
#ifdef LIBXML_SAX1_ENABLED
11281162
err |= testBalancedChunk();

0 commit comments

Comments
 (0)