xml: improve cdata and comment callback logic - tscrape - twitter scraper
 (HTM) git clone git://git.codemadness.org/tscrape
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 797f715398aeac08febc8067ed6423da727e4f45
 (DIR) parent 51995d6fc4760fadac68650bb82773b9bf9eae79
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Fri,  2 Aug 2019 18:46:06 +0200
       
       xml: improve cdata and comment callback logic
       
       it used to call both handlers twice at the end for "-->" (comment) or "]]>"
       (CDATA) with the data "" and length 0.
       
       Now it is only called when non-empty. The start and end handlers can still be
       used.
       
       Diffstat:
         M xml.c                               |       4 ++--
       
       1 file changed, 2 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/xml.c b/xml.c
       @@ -126,7 +126,7 @@ xml_parsecomment(XMLParser *x)
                        x->xmlcommentstart(x);
                while ((c = GETNEXT()) != EOF) {
                        if (c == '-' || c == '>') {
       -                        if (x->xmlcomment) {
       +                        if (x->xmlcomment && datalen) {
                                        x->data[datalen] = '\0';
                                        x->xmlcomment(x, x->data, datalen);
                                        datalen = 0;
       @@ -175,7 +175,7 @@ xml_parsecdata(XMLParser *x)
                        x->xmlcdatastart(x);
                while ((c = GETNEXT()) != EOF) {
                        if (c == ']' || c == '>') {
       -                        if (x->xmlcdata) {
       +                        if (x->xmlcdata && datalen) {
                                        x->data[datalen] = '\0';
                                        x->xmlcdata(x, x->data, datalen);
                                        datalen = 0;