sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit b7e14e7b79a73f69044d91c6af6cf8b62e82437c
parent 4f40df3788165a137bc60bb6c0fd96af0c248c35
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 11 Mar 2018 16:32:37 +0100

xml: improve comment parsing

note that ---> is officially invalid XML, but we allow it anyway.

Diffstat:
Mxml.c | 39++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/xml.c b/xml.c @@ -107,36 +107,41 @@ xml_parseattrs(XMLParser *x) static void xml_parsecomment(XMLParser *x) { - static const char *end = "-->"; size_t datalen = 0, i = 0; - char tmp[4]; int c; if (x->xmlcommentstart) x->xmlcommentstart(x); while ((c = x->getnext()) != EOF) { - if (c == end[i]) { - if (end[++i] == '\0') { /* end */ + if (c == '-' || c == '>') { + if (x->xmlcomment) { x->data[datalen] = '\0'; + x->xmlcomment(x, x->data, datalen); + datalen = 0; + } + } + + if (c == '-') { + if (++i > 2) { if (x->xmlcomment) - x->xmlcomment(x, x->data, datalen); - if (x->xmlcommentend) - x->xmlcommentend(x); - return; + for (; i > 2; i--) + x->xmlcomment(x, "-", 1); + i = 2; } + continue; + } else if (c == '>' && i == 2) { + if (x->xmlcommentend) + x->xmlcommentend(x); + return; } else if (i) { if (x->xmlcomment) { - x->data[datalen] = '\0'; - if (datalen) - x->xmlcomment(x, x->data, datalen); - memcpy(tmp, end, i); - tmp[i] = '\0'; - x->xmlcomment(x, tmp, i); + for (; i > 0; i--) + x->xmlcomment(x, "-", 1); } i = 0; - x->data[0] = c; - datalen = 1; - } else if (datalen < sizeof(x->data) - 1) { + } + + if (datalen < sizeof(x->data) - 1) { x->data[datalen++] = c; } else { x->data[datalen] = '\0';