From: Jim Hague Date: Tue, 12 Dec 2017 21:08:29 +0000 (+0000) Subject: eit: Allow empty match subexpressions (#4787) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3b232b66e02fc46f1e7e97efb5ef48c6968cf779;p=thirdparty%2Ftvheadend.git eit: Allow empty match subexpressions (#4787) If a scrape regex includes a subexpression matching the null string (), this match is treated as if the regex did not match. Amend this to return an empty string as the match; this is plainly what the regex author wanted. As an example of why this might be wanted, consider the UK Freeview extraction of a subtitle from the summary. A user might wish to specify the subtitle is left blank if not obvious subtitle is present in the summary. Issue: #4787. --- diff --git a/src/epggrab/module/eitpatternlist.c b/src/epggrab/module/eitpatternlist.c index 4ace40e36..76d87b59f 100644 --- a/src/epggrab/module/eitpatternlist.c +++ b/src/epggrab/module/eitpatternlist.c @@ -56,16 +56,14 @@ void *eit_pattern_apply_list(char *buf, size_t size_buf, const char *text, eit_p TAILQ_FOREACH(p, l, p_links) if (!regexec(&p->compiled, text, 2, match, 0) && match[1].rm_so != -1) { size = MIN(match[1].rm_eo - match[1].rm_so, size_buf - 1); - if (size <= 0) - continue; - while (isspace(text[match[1].rm_so + size - 1])) - size--; - memcpy(buf, text + match[1].rm_so, size); - buf[size] = '\0'; - if (size) { - tvhtrace(LS_EPGGRAB," pattern \"%s\" matches with '%s'", p->text, buf); - return buf; + if (size > 0) { + while (isspace(text[match[1].rm_so + size - 1])) + size--; + memcpy(buf, text + match[1].rm_so, size); } + buf[size] = '\0'; + tvhtrace(LS_EPGGRAB," pattern \"%s\" matches with '%s'", p->text, buf); + return buf; } return NULL; }