Skip to content

Commit

Permalink
Handle trailing whitespace in tag values
Browse files Browse the repository at this point in the history
Signed-off-by: Nikola Forró <[email protected]>
  • Loading branch information
nforro committed Jul 2, 2024
1 parent 1a40ae6 commit ea9a85b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions specfile/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ def regex_pattern(tag):
data = []
buffer: List[str] = []
for line, valid in lines:
ws = ""
tokens = re.split(r"([^\S\n]+)$", line, maxsplit=1)
if len(tokens) > 1:
line, ws, _ = tokens
line, prefix, suffix = split_conditional_macro_expansion(line)
# find out if there is a match for one of the tag regexes
m = next((m for m in (r.match(line) for r in tag_regexes) if m), None)
Expand All @@ -511,13 +515,13 @@ def regex_pattern(tag):
Comments.parse(buffer),
valid,
prefix,
suffix,
suffix + ws,
context,
)
)
buffer = []
else:
buffer.append(prefix + line + suffix)
buffer.append(prefix + line + suffix + ws)
return cls(data, buffer)

def get_raw_section_data(self) -> List[str]:
Expand Down
14 changes: 11 additions & 3 deletions tests/unit/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_parse():
"Epoch: 1",
"%endif",
"",
"Requires: make",
"Requires: make ",
"Requires(post): bash",
"",
"Provides: testX = %{version}-%{release}",
Expand Down Expand Up @@ -102,7 +102,15 @@ def test_get_raw_section_data():
Comments([Comment("this is a valid comment", " # ")]),
),
Tag("Epoch", "1", ": ", Comments([], ["", "%if 0"])),
Tag("Requires", "make", ": ", Comments([], ["%endif", ""])),
Tag(
"Requires",
"make",
": ",
Comments([], ["%endif", ""]),
True,
"",
" ",
),
Tag("Requires(post)", "bash", ": ", Comments()),
Tag(
"Suggests",
Expand Down Expand Up @@ -133,7 +141,7 @@ def test_get_raw_section_data():
"Epoch: 1",
"%endif",
"",
"Requires: make",
"Requires: make ",
"Requires(post): bash",
"",
"%{?fedora:Suggests: diffutils}",
Expand Down

0 comments on commit ea9a85b

Please sign in to comment.