Fix #1517 - escape regexp special chars before adding autorec rule.

This stops autorec rules entered from event failing to detect events.
This commit is contained in:
Adam Sutton 2013-01-19 01:30:24 +00:00
parent 87822f001f
commit 97c739b572
3 changed files with 40 additions and 1 deletions

View file

@ -559,9 +559,11 @@ void dvr_autorec_add_series_link
( const char *dvr_config_name, epg_broadcast_t *event,
const char *creator, const char *comment )
{
char *title;
if (!event || !event->episode) return;
title = regexp_escape(epg_broadcast_get_title(event, NULL));
_dvr_autorec_add(dvr_config_name,
epg_broadcast_get_title(event, NULL),
title,
event->channel,
NULL, 0, // tag/content type
NULL,
@ -569,6 +571,8 @@ void dvr_autorec_add_series_link
event->serieslink,
0, NULL,
creator, comment);
if (title)
free(title);
}

View file

@ -561,6 +561,8 @@ int makedirs ( const char *path, int mode );
int rmtree ( const char *path );
char *regexp_escape ( const char *str );
/* printing */
#if __SIZEOF_LONG__ == 8
#define PRItime_t PRId64

View file

@ -403,3 +403,36 @@ rmtree ( const char *path )
err = rmdir(path);
return err;
}
char *
regexp_escape(const char* str)
{
const char *a;
char *tmp, *b;
if (!str)
return NULL;
a = str;
b = tmp = malloc(strlen(str) * 2);
while (*a) {
switch (*a) {
case '?':
case '+':
case '.':
case '(':
case ')':
case '[':
case ']':
case '*':
*b = '\\';
b++;
/* -fallthrough */
default:
break;
}
*b = *a;
b++;
a++;
}
*b = 0;
return tmp;
}