Skip empty, invalid and comment lines in adblock_parse_line

This commit is contained in:
Christian Dywan 2012-03-06 20:14:15 +01:00
parent a83cea4964
commit fa22841ec9

View file

@ -1301,12 +1301,10 @@ adblock_frame_add_private (const gchar* line,
static gchar* static gchar*
adblock_parse_line (gchar* line) adblock_parse_line (gchar* line)
{ {
if (!line) /* Skip invalid, empty and comment lines */
return NULL; if (!(line && line[0] != ' ' && line[0] != '!' && line[0]))
g_strchomp (line);
/* Ignore comments and new lines */
if (line[0] == '!')
return NULL; return NULL;
/* FIXME: No support for whitelisting */ /* FIXME: No support for whitelisting */
if (line[0] == '@' && line[1] == '@') if (line[0] == '@' && line[1] == '@')
return NULL; return NULL;
@ -1314,9 +1312,7 @@ adblock_parse_line (gchar* line)
if (line[0] == '[') if (line[0] == '[')
return NULL; return NULL;
/* Skip garbage */ g_strchomp (line);
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] == '#' )
@ -1334,13 +1330,13 @@ adblock_parse_line (gchar* line)
adblock_frame_add_private (line, "##"); adblock_frame_add_private (line, "##");
return NULL; return NULL;
} }
/* Got per domain CSS hider rule. Workaround */ /* Got per domain CSS hider rule. Workaround */
if (strchr (line, '#')) if (strchr (line, '#'))
{ {
adblock_frame_add_private (line, "#"); adblock_frame_add_private (line, "#");
return NULL; return NULL;
} }
/* Got URL blocker rule */ /* Got URL blocker rule */
if (line[0] == '|' && line[1] == '|' ) if (line[0] == '|' && line[1] == '|' )
{ {