Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: abp/filters/parser.py

Issue 29901579: Issue 6976 - Ignore invalid headers instead of crashing (Closed) Base URL: https://hg.adblockplus.org/python-abp
Patch Set: Created Oct. 4, 2018, 1:34 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/test_parser.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: abp/filters/parser.py
===================================================================
--- a/abp/filters/parser.py
+++ b/abp/filters/parser.py
@@ -137,18 +137,17 @@
Comment = _line_type('Comment', 'text', '! {.text}')
Metadata = _line_type('Metadata', 'key value', '! {0.key}: {0.value}')
Filter = _line_type('Filter', 'text selector action options', '{.text}')
Include = _line_type('Include', 'target', '%include {0.target}%')
METADATA_REGEXP = re.compile(r'\s*!\s*(.*?)\s*:\s*(.*)')
INCLUDE_REGEXP = re.compile(r'%include\s+(.+)%')
-HEADER_REGEXP = re.compile(r'\[(?:(Adblock(?:\s*Plus\s*[\d\.]+?)?)|.*)\]',
- flags=re.I)
+HEADER_REGEXP = re.compile(r'\[(Adblock(?:\s*Plus\s*[\d\.]+?)?)\]', flags=re.I)
HIDING_FILTER_REGEXP = re.compile(r'^([^/*|@"!]*?)#([@?])?#(.+)$')
FILTER_OPTIONS_REGEXP = re.compile(
r'\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$'
)
def _parse_instruction(text):
match = INCLUDE_REGEXP.match(text)
@@ -289,20 +288,17 @@
stripped = line.strip()
if stripped == '':
return EmptyLine()
if position == 'start':
match = HEADER_REGEXP.search(line)
if match:
- version = match.group(1)
- if not version:
- raise ParseError('Malformed header', line)
- return Header(version)
+ return Header(match.group(1))
if stripped.startswith('!'):
match = METADATA_REGEXP.match(line)
if match:
key, value = match.groups()
if position != 'body' or key.lower() == 'checksum':
return Metadata(key, value)
return Comment(stripped[1:].lstrip())
« no previous file with comments | « no previous file | tests/test_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld