Skip to content

Commit 3569ab6

Browse files
Merge pull request #191 from packit/sections
Fix a bug in section parsing Related to #184. The bug was catched by rebase-helper test suite. We should run it on every specfile PR. RELEASE NOTES BEGIN Fixed a bug in section parsing that caused sections to be ignored when there were macro definitions spread across the spec file and not cumulated at the top. RELEASE NOTES END Reviewed-by: Maja Massarini <None> Reviewed-by: Laura Barcziová <None>
2 parents 032a6e2 + 9712f08 commit 3569ab6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

specfile/sections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def split_id(line):
263263
macro_definitions = MacroDefinitions.parse(lines)
264264
for md in macro_definitions:
265265
position = md.get_position(macro_definitions)
266-
excluded_lines.append(range(position, position + len(md.get_raw_data())))
266+
excluded_lines.append(range(position, position + len(md.body.splitlines())))
267267
section_id_regexes = [
268268
re.compile(rf"^%{re.escape(n)}(\s+.*(?<!\\)$|$)", re.IGNORECASE)
269269
for n in SECTION_NAMES

tests/unit/test_sections.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ def test_parse_macro_definitions():
125125
"",
126126
"%description -n %{1}",
127127
"Subpackage %{1}.}",
128+
"",
129+
"%prep",
130+
"%autosetup",
128131
]
129132
)
130-
assert len(sections) == 3
133+
assert len(sections) == 4
131134
assert sections[1].id == "package -n test"
135+
assert sections[-1].id == "prep"
132136

133137

134138
def test_get_raw_data():

0 commit comments

Comments
 (0)