sfeed

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

commit 1c62d0d8b7162e501372a3b192630d2a62a7fa8b
parent d3933ef3d7f84e3bc85b66025b4822ebbd753ed8
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon, 22 Jun 2015 23:56:43 +0200

xml: fix cdata issue

Diffstat:
Mxml.c | 51+++++++++++++--------------------------------------
1 file changed, 13 insertions(+), 38 deletions(-)

diff --git a/xml.c b/xml.c @@ -196,60 +196,35 @@ xmlparser_parsecomment(XMLParser *x) } } -/* TODO: - * <test><![CDATA[1234567dddd8]]> - * - * with x->data of sizeof(15) gives 2 ] at end of cdata, should be 1 - * test comment function too for similar bug? - * - */ static __inline__ void xmlparser_parsecdata(XMLParser *x) { static const char *end = "]]>"; static const size_t endsiz = sizeof(end); size_t datalen = 0, i = 0; + char tmp[4]; int c; if(x->xmlcdatastart) x->xmlcdatastart(x); while((c = xmlparser_getnext(x)) != EOF) { - if(c == end[i++]) { - if(!end[i]) { /* end of match */ - if(datalen >= endsiz) { - datalen -= endsiz; - x->data[datalen] = '\0'; - } + if(c == end[i]) { + if(end[++i] == '\0') { /* end */ + x->data[datalen] = '\0'; if(x->xmlcdata) x->xmlcdata(x, x->data, datalen); - if(x->xmlcdataend) - x->xmlcdataend(x); - break; + return; } - continue; - } else { - i = 0; - } -#if 0 - if(c == ']' && i < 2) { - i++; - } else if(c == '>') { - if(i == 2) { /* ]] */ - if(datalen >= 2) { - datalen -= 2; - x->data[datalen] = '\0'; - if(x->xmlcdata) - x->xmlcdata(x, x->data, datalen); - } - if(x->xmlcdataend) - x->xmlcdataend(x); - break; + } else if(i) { + if(x->xmlcdata) { + memcpy(tmp, end, i); + tmp[i] = '\0'; + x->xmlcdata(x, tmp, i); } i = 0; - } -#endif - /* TODO: what if the end has ]>, and it's cut on the boundary */ - if(datalen < sizeof(x->data) - 1) { + x->data[0] = c; + datalen = 1; + } else if(datalen < sizeof(x->data) - 1) { x->data[datalen++] = c; } else { x->data[datalen] = '\0';