Skip to content

Commit 5ff74b7

Browse files
committed
mask: improve parsing of empty header line
If the header of mask had a break, which looked like `#`, it would fail to parse, which is somewhat wrong. So add it as exception. Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 4f5c629 commit 5ff74b7

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/pkgdev/scripts/pkgdev_mask.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def parse(self):
160160
comment = []
161161
i = mask_lines[0] - 2
162162
while i >= 0 and (line := lines[i].rstrip()):
163-
if not line.startswith('# '):
163+
if not line.startswith('# ') and line != '#':
164164
mask.error(f'invalid mask entry header, lineno {i + 1}: {line!r}')
165165
comment.append(line[2:])
166166
i -= 1
@@ -274,8 +274,7 @@ def _mask(options, out, err):
274274

275275
if options.rites:
276276
removal_date = today + timedelta(days=options.rites)
277-
removal = removal_date.strftime('%Y-%m-%d')
278-
mask_args['comment'].append(f'Removal: {removal}')
277+
mask_args['comment'].append(f'Removal: {removal_date:%Y-%m-%d}')
279278

280279
m = Mask(**mask_args)
281280
mask_file.add(m)

tests/scripts/test_pkgdev_mask.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,29 @@ def test_existing_masks(self):
194194
self.script()
195195
assert self.profile.masks == frozenset([atom_cls('cat/masked'), atom_cls('=cat/pkg-0')])
196196

197+
def test_invalid_header(self, capsys):
198+
self.masks_path.write_text(textwrap.dedent("""\
199+
# Random Dev <random.dev@email.com> (2022-09-09)
200+
#
201+
# Larry the Cow was here
202+
#
203+
# masked
204+
cat/masked
205+
206+
# Larry the Cow <larry@gentoo.org> (2022-09-09)
207+
#test
208+
# Larry the Cow wasn't here
209+
cat/masked2
210+
"""))
211+
212+
with os_environ(EDITOR="sed -i '1s/$/mask comment/'"), \
213+
patch('sys.argv', self.args + ['=cat/pkg-0']), \
214+
pytest.raises(SystemExit), \
215+
chdir(pjoin(self.repo.path)):
216+
self.script()
217+
_, err = capsys.readouterr()
218+
assert 'invalid mask entry header, lineno 9' in err
219+
197220
def test_invalid_author(self, capsys):
198221
for line in (
199222
'# Random Dev <random.dev@email.com>',

0 commit comments

Comments
 (0)