commit f250a75b11007ccfa973953ab437757403444646 from: Omar Polo date: Sat Mar 06 19:10:19 2021 UTC [gemtext] improve parse_link * add a mising `&& isspace(buf[0])' that would make the parser skip the link label * swap alt and line: line is the text, alt the URL * text is always defined, at worst is a copy of URL commit - 4dd664cea4f1c5745dac573900e48c1fee5ab151 commit + f250a75b11007ccfa973953ab437757403444646 blob - d9122de6004c046a2708f6e775be460fdbe46cd4 blob + 267a1d8e7214cfcf5278c961b470d5f94c6629bd --- gemtext.c +++ gemtext.c @@ -125,21 +125,26 @@ parse_link(struct parser *p, enum line_type t, const c memcpy(u, url_start, buf - url_start); if (len == 0) - return emit_line(p, t, u, NULL); + goto nolabel; - while (len > 0) { + while (len > 0 && isspace(buf[0])) { buf++; len--; } if (len == 0) - return emit_line(p, t, u, NULL); + goto nolabel; if ((l = calloc(1, len + 1)) == NULL) return 0; memcpy(l, buf, len); - return emit_line(p, t, u, l); + return emit_line(p, t, l, u); + +nolabel: + if ((l = strdup(u)) == NULL) + return 0; + return emit_line(p, t, l, u); } static int