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

Side by Side Diff: abp/filters/parser.py

Issue 29879650: Issue 6950 - Don't include headers and metadata from includes into output (Closed)
Patch Set: Test for "Last modified" Created Sept. 14, 2018, 3:32 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | abp/filters/renderer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 134
135 Header = _line_type('Header', 'version', '[{.version}]') 135 Header = _line_type('Header', 'version', '[{.version}]')
136 EmptyLine = _line_type('EmptyLine', '', '') 136 EmptyLine = _line_type('EmptyLine', '', '')
137 Comment = _line_type('Comment', 'text', '! {.text}') 137 Comment = _line_type('Comment', 'text', '! {.text}')
138 Metadata = _line_type('Metadata', 'key value', '! {0.key}: {0.value}') 138 Metadata = _line_type('Metadata', 'key value', '! {0.key}: {0.value}')
139 Filter = _line_type('Filter', 'text selector action options', '{.text}') 139 Filter = _line_type('Filter', 'text selector action options', '{.text}')
140 Include = _line_type('Include', 'target', '%include {0.target}%') 140 Include = _line_type('Include', 'target', '%include {0.target}%')
141 141
142 142
143 METADATA_REGEXP = re.compile(r'([\w-]+)\s*:\s*(.*)') 143 METADATA_REGEXP = re.compile(r'(.*?)\s*:\s*(.*)')
144 INCLUDE_REGEXP = re.compile(r'%include\s+(.+)%') 144 INCLUDE_REGEXP = re.compile(r'%include\s+(.+)%')
145 HEADER_REGEXP = re.compile(r'\[(Adblock(?:\s*Plus\s*[\d\.]+?)?)\]', flags=re.I) 145 HEADER_REGEXP = re.compile(r'\[(Adblock(?:\s*Plus\s*[\d\.]+?)?)\]', flags=re.I)
146 HIDING_FILTER_REGEXP = re.compile(r'^([^/*|@"!]*?)#([@?])?#(.+)$') 146 HIDING_FILTER_REGEXP = re.compile(r'^([^/*|@"!]*?)#([@?])?#(.+)$')
147 FILTER_OPTIONS_REGEXP = re.compile( 147 FILTER_OPTIONS_REGEXP = re.compile(
148 r'\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$' 148 r'\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$'
149 ) 149 )
150 150
151 151
152 def _parse_header(text): 152 def _parse_header(text):
153 match = HEADER_REGEXP.match(text) 153 match = HEADER_REGEXP.match(text)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 Thrown during iteration for invalid filter list lines. 312 Thrown during iteration for invalid filter list lines.
313 TypeError 313 TypeError
314 If `lines` is not iterable. 314 If `lines` is not iterable.
315 315
316 """ 316 """
317 metadata_closed = False 317 metadata_closed = False
318 318
319 for line in lines: 319 for line in lines:
320 result = parse_line(line) 320 result = parse_line(line)
321 321
322 if isinstance(result, Comment): 322 if result.type == 'comment':
323 match = METADATA_REGEXP.match(result.text) 323 match = METADATA_REGEXP.match(result.text)
324 if match: 324 if match:
325 key, value = match.groups() 325 key, value = match.groups()
326 326
327 # Historically, checksums can occur at the bottom of the 327 # Historically, checksums can occur at the bottom of the
328 # filter list. Checksums are no longer used by Adblock Plus, 328 # filter list. Checksums are no longer used by Adblock Plus,
329 # but in order to strip them (in abp.filters.renderer), 329 # but in order to strip them (in abp.filters.renderer),
330 # we have to make sure to still parse them regardless of 330 # we have to make sure to still parse them regardless of
331 # their position in the filter list. 331 # their position in the filter list.
332 if not metadata_closed or key.lower() == 'checksum': 332 if not metadata_closed or key.lower() == 'checksum':
333 yield Metadata(key, value) 333 result = Metadata(key, value)
334 continue
335 334
336 if not result.text: 335 if result.type not in {'header', 'metadata'}:
337 metadata_closed = True
338 elif not isinstance(result, Header):
339 metadata_closed = True 336 metadata_closed = True
340 337
341 yield result 338 yield result
OLDNEW
« no previous file with comments | « no previous file | abp/filters/renderer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld