Skip to content

Commit

Permalink
Ignore unparseable %changelog lines when checking for %autochangelog (#…
Browse files Browse the repository at this point in the history
…387)

Ignore unparseable %changelog lines when checking for %autochangelog

Fixes #386.
RELEASE NOTES BEGIN
Fixed an exception that occured when accessing the Specfile.has_autochangelog property while having unparseable lines (e.g. lines ending with unescaped %) in %changelog.
RELEASE NOTES END

Reviewed-by: Laura Barcziová
  • Loading branch information
softwarefactory-project-zuul[bot] authored Jun 24, 2024
2 parents 45325ef + 18370f4 commit 6137959
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
22 changes: 15 additions & 7 deletions specfile/specfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

from specfile.changelog import Changelog, ChangelogEntry, guess_packager
from specfile.context_management import ContextManager
from specfile.exceptions import SourceNumberException, SpecfileException
from specfile.exceptions import (
SourceNumberException,
SpecfileException,
UnterminatedMacroException,
)
from specfile.formatter import formatted
from specfile.macro_definitions import (
CommentOutStyle,
Expand Down Expand Up @@ -433,12 +437,16 @@ def contains_autochangelog(section: Section) -> bool:
if line.lstrip().startswith("#"):
# skip comments
continue
for node in ValueParser.flatten(ValueParser.parse(line)):
if (
isinstance(node, (MacroSubstitution, EnclosedMacroSubstitution))
and node.name == "autochangelog"
):
return True
try:
for node in ValueParser.flatten(ValueParser.parse(line)):
if (
isinstance(node, (MacroSubstitution, EnclosedMacroSubstitution))
and node.name == "autochangelog"
):
return True
except UnterminatedMacroException:
# ignore unparseable lines
continue
return False

@property
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/test_specfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ def test_autorelease(spec_rpmautospec, raw_release, has_autorelease):
@pytest.mark.skipif(
rpm.__version__ < "4.16", reason="%autochangelog requires rpm 4.16 or higher"
)
def test_autochangelog(spec_rpmautospec, spec_conditionalized_changelog):
def test_autochangelog(
spec_rpmautospec, spec_conditionalized_changelog, spec_autosetup
):
spec = Specfile(spec_rpmautospec)
assert spec.has_autochangelog
with spec.changelog() as changelog:
Expand All @@ -350,6 +352,10 @@ def test_autochangelog(spec_rpmautospec, spec_conditionalized_changelog):
assert changelogs[0] == changelog
with spec.changelog(changelogs[1]) as changelog:
assert changelog[-1].content == ["test"]
spec = Specfile(spec_autosetup)
with spec.changelog() as changelog:
changelog[0].content += "%"
assert not spec.has_autochangelog


@pytest.mark.skipif(
Expand Down

0 comments on commit 6137959

Please sign in to comment.