Skip to content

Commit 1e5f02a

Browse files
committed
Fix parsing Source and Patch tags
It is necessary to use a more specific regex when searching for a match in parsed section, otherwise expanded_value could end up being mismatched. Signed-off-by: Nikola Forró <[email protected]>
1 parent cfcee55 commit 1e5f02a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

specfile/tags.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def parse(raw_section: Section, parsed_section: Optional[Section] = None) -> "Ta
582582

583583
def regex_pattern(tag):
584584
name = re.escape(tag)
585-
index = r"\d?" if tag in ["Source", "Patch"] else ""
585+
index = r"\d*" if tag in ["Source", "Patch"] else ""
586586
return rf"^(?P<n>{name}{index})(?P<s>\s*:\s*)(?P<v>.+)"
587587

588588
tag_regexes = [re.compile(regex_pattern(t), re.IGNORECASE) for t in TAG_NAMES]
@@ -593,8 +593,13 @@ def regex_pattern(tag):
593593
m = next((m for m in (r.match(line) for r in tag_regexes) if m), None)
594594
if m:
595595
# find out if any line in the parsed section matches the same regex
596+
tag_regex = re.compile(regex_pattern(m.group("n")))
596597
e = next(
597-
(e for e in (m.re.match(pl) for pl in parsed_section or []) if e),
598+
(
599+
e
600+
for e in (tag_regex.match(pl) for pl in parsed_section or [])
601+
if e
602+
),
598603
None,
599604
)
600605
expanded_value = e.group("v") if e else None

0 commit comments

Comments
 (0)