Skip to content

Commit

Permalink
tree: Fix handling of empty strings in xmlNodeParseContent
Browse files Browse the repository at this point in the history
We shouldn't create an empty text node to match the old behavior.

Fixes #759.
  • Loading branch information
nwellnhof committed Jul 3, 2024
1 parent 46ec621 commit 944cc23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions testparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@

#include <string.h>

static int
testNewDocNode(void) {
xmlNodePtr node;
int err = 0;

node = xmlNewDocNode(NULL, NULL, BAD_CAST "c", BAD_CAST "");
if (node->children != NULL) {
fprintf(stderr, "empty node has children\n");
err = 1;
}
xmlFreeNode(node);

return err;
}

static int
testStandaloneWithEncoding(void) {
xmlDocPtr doc;
Expand Down Expand Up @@ -631,6 +646,7 @@ int
main(void) {
int err = 0;

err |= testNewDocNode();
err |= testStandaloneWithEncoding();
err |= testUnsupportedEncoding();
err |= testNodeGetContent();
Expand Down
2 changes: 1 addition & 1 deletion tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ xmlNodeParseContentInternal(const xmlDoc *doc, xmlNodePtr parent,
else
remaining = len;

if (value == NULL)
if ((value == NULL) || (value[0] == 0))
goto done;

cur = value;
Expand Down

0 comments on commit 944cc23

Please sign in to comment.