Skip empty lines in adblock rules files

This commit is contained in:
Alexander Butenko 2011-06-18 09:45:20 -04:00 committed by Christian Dywan
parent ebf892e2de
commit f093e55f85

View file

@ -1045,7 +1045,7 @@ adblock_fixup_regexp (const gchar* prefix,
{ {
gchar* dst; gchar* dst;
GString* str; GString* str;
int len; int len = 0;
if (!src) if (!src)
return NULL; return NULL;
@ -1087,13 +1087,12 @@ adblock_fixup_regexp (const gchar* prefix,
break; break;
} }
src++; src++;
len++;
} }
while (*src); while (*src);
dst = g_strdup (str->str); dst = g_string_free (str, FALSE);
g_string_free (str, TRUE);
/* We dont need .* in the end of url. Thats stupid */ /* We dont need .* in the end of url. Thats stupid */
len = strlen (dst);
if (dst && dst[len-1] == '*' && dst[len-2] == '.') if (dst && dst[len-1] == '*' && dst[len-2] == '.')
{ {
dst[len-2] = '\0'; dst[len-2] = '\0';
@ -1112,6 +1111,9 @@ adblock_compile_regexp (GHashTable* tbl,
int pos = 0; int pos = 0;
gchar *sig; gchar *sig;
if (!patt)
return;
/* TODO: Play with optimization flags */ /* TODO: Play with optimization flags */
regex = g_regex_new (patt, G_REGEX_OPTIMIZE, regex = g_regex_new (patt, G_REGEX_OPTIMIZE,
G_REGEX_MATCH_NOTEMPTY, &error); G_REGEX_MATCH_NOTEMPTY, &error);
@ -1167,15 +1169,17 @@ adblock_add_url_pattern (gchar* prefix,
gchar* format_patt; gchar* format_patt;
gchar* opts; gchar* opts;
g_test_timer_start ();
data = g_strsplit (line, "$", -1); data = g_strsplit (line, "$", -1);
if (data && data[0] && data[1] && data[2]) if (!data || !data[0])
return NULL;
if (data[1] && data[2])
{ {
patt = g_strconcat (data[0], data[1], NULL); patt = g_strconcat (data[0], data[1], NULL);
opts = g_strdup_printf ("t=%s,r=%s,%s", type, patt, data[2]); opts = g_strdup_printf ("t=%s,r=%s,%s", type, patt, data[2]);
g_strfreev (data); g_strfreev (data);
} }
else if (data && data[0] && data[1]) else if (data[1])
{ {
patt = data[0]; patt = data[0];
opts = g_strdup_printf ("t=%s,r=%s,%s", type, patt, data[1]); opts = g_strdup_printf ("t=%s,r=%s,%s", type, patt, data[1]);
@ -1268,6 +1272,10 @@ adblock_parse_line (gchar* line)
if (line[0] == '[') if (line[0] == '[')
return NULL; return NULL;
/* Skip garbage */
if (line[0] == ' ' || !line[0])
return NULL;
/* Got CSS block hider */ /* Got CSS block hider */
if (line[0] == '#' && line[1] == '#' ) if (line[0] == '#' && line[1] == '#' )
{ {