From a76c5f40bd3dcf584314a60ec6683383f82ebb94 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sun, 17 Apr 2011 14:05:55 +0300 Subject: [PATCH] Fix HTML tag detection --- examples/upskirt.c | 2 +- render/xhtml.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/examples/upskirt.c b/examples/upskirt.c index b887076..16dac1e 100644 --- a/examples/upskirt.c +++ b/examples/upskirt.c @@ -34,7 +34,7 @@ main(int argc, char **argv) size_t ret; FILE *in = stdin; struct mkd_renderer renderer; - size_t i, iterations = 20000; + size_t i, iterations = 1; /* opening the file if given from the command line */ if (argc > 1) { diff --git a/render/xhtml.c b/render/xhtml.c index e67a95d..d434acd 100755 --- a/render/xhtml.c +++ b/render/xhtml.c @@ -68,17 +68,34 @@ lus_attr_escape(struct buf *ob, const char *src, size_t size) static int is_html_tag(struct buf *tag, const char *tagname) { - size_t i; + size_t i = 0; - for (i = 0; i < tag->size; ++i) { - if (tagname[i] == '>') + if (i < tag->size && tag->data[0] != '<') + return 0; + + i++; + + while (i < tag->size && isspace(tag->data[i])) + i++; + + if (i < tag->size && tag->data[i] == '/') + i++; + + while (i < tag->size && isspace(tag->data[i])) + i++; + + for (; i < tag->size; ++i, ++tagname) { + if (*tagname == 0) break; - if (tag->data[i] != tagname[i]) + if (tag->data[i] != *tagname) return 0; } - return (i == tag->size || isspace(tag->data[i]) || tag->data[i] == '>'); + if (i == tag->size) + return 0; + + return (isspace(tag->data[i]) || tag->data[i] == '>'); } /******************** @@ -339,13 +356,13 @@ rndr_raw_html(struct buf *ob, struct buf *text, void *opaque) if (options->flags & XHTML_SKIP_HTML) escape_html = 1; - else if ((options->flags & XHTML_SKIP_STYLE) != 0 && is_html_tag(text, "