Skip to content

Commit e20e7d1

Browse files
Merge pull request #195 from packit/changelog
Fix parsing of changelog entries Asterisk as the first character on a line doesn't always denote a next changelog entry header, unless there is some non-whitespace content preceding it, it is taken as part of the content. Reviewed-by: Jiri Popelka <None>
2 parents 5efca5e + a8f3842 commit e20e7d1

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

specfile/changelog.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,14 @@ def extract_following_lines(content):
331331
content: List[str] = []
332332
for line in section:
333333
if line.startswith("*"):
334-
if header:
335-
following_lines = extract_following_lines(content)
336-
data.insert(0, ChangelogEntry(header, content, following_lines))
337-
header = line
338-
content = []
334+
if header is None or "".join(content).strip():
335+
if header:
336+
following_lines = extract_following_lines(content)
337+
data.insert(0, ChangelogEntry(header, content, following_lines))
338+
header = line
339+
content = []
340+
else:
341+
content.append(line)
339342
elif header:
340343
content.append(line)
341344
else:

tests/unit/test_changelog.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ def test_parse():
141141
Section(
142142
"changelog",
143143
data=[
144+
"* Fri Jan 27 2023 Nikola Forró <[email protected]> - 0.4-1",
145+
"",
146+
"* this is also a valid entry",
147+
"",
148+
"* Fri Jan 27 2023 Nikola Forró <[email protected]> - 0.3-2",
149+
"* this is a valid entry",
150+
"",
144151
"* Mon Nov 21 2022 Nikola Forró <[email protected]> - 0.3-1",
145152
"- this is a formatted",
146153
" changelog entry",
@@ -162,7 +169,7 @@ def test_parse():
162169
],
163170
)
164171
)
165-
assert len(changelog) == 5
172+
assert len(changelog) == 7
166173
assert (
167174
changelog[0].header
168175
== "* Tue May 04 2021 Nikola Forró <[email protected]> - 0.1-1"
@@ -200,6 +207,23 @@ def test_parse():
200207
"- here is another item",
201208
]
202209
assert not changelog[4].extended_timestamp
210+
assert (
211+
changelog[5].header
212+
== "* Fri Jan 27 2023 Nikola Forró <[email protected]> - 0.3-2"
213+
)
214+
assert changelog[5].content == [
215+
"* this is a valid entry",
216+
]
217+
assert not changelog[5].extended_timestamp
218+
assert (
219+
changelog[6].header
220+
== "* Fri Jan 27 2023 Nikola Forró <[email protected]> - 0.4-1"
221+
)
222+
assert changelog[6].content == [
223+
"",
224+
"* this is also a valid entry",
225+
]
226+
assert not changelog[6].extended_timestamp
203227

204228

205229
def test_get_raw_section_data():
@@ -242,9 +266,33 @@ def test_get_raw_section_data():
242266
],
243267
"0.3-1",
244268
),
269+
ChangelogEntry.assemble(
270+
datetime.date(2023, 1, 27),
271+
"Nikola Forró <[email protected]>",
272+
[
273+
"* this is a valid entry",
274+
],
275+
"0.3-2",
276+
),
277+
ChangelogEntry.assemble(
278+
datetime.date(2023, 1, 27),
279+
"Nikola Forró <[email protected]>",
280+
[
281+
"",
282+
"* this is also a valid entry",
283+
],
284+
"0.4-1",
285+
),
245286
]
246287
)
247288
assert changelog.get_raw_section_data() == [
289+
"* Fri Jan 27 2023 Nikola Forró <[email protected]> - 0.4-1",
290+
"",
291+
"* this is also a valid entry",
292+
"",
293+
"* Fri Jan 27 2023 Nikola Forró <[email protected]> - 0.3-2",
294+
"* this is a valid entry",
295+
"",
248296
"* Mon Nov 21 2022 Nikola Forró <[email protected]> - 0.3-1",
249297
"- this is a formatted",
250298
" changelog entry",

0 commit comments

Comments
 (0)