diff --git a/specfile/conditions.py b/specfile/conditions.py index 257ac92..e56c2e8 100644 --- a/specfile/conditions.py +++ b/specfile/conditions.py @@ -82,7 +82,7 @@ def process_conditions( if macro_definitions: for md in macro_definitions: position = md.get_position(macro_definitions) - excluded_lines.append(range(position, position + len(md.body.splitlines()))) + excluded_lines.append(range(position, position + len(md.body.split("\n")))) condition_regex = re.compile( r""" ^ diff --git a/specfile/macro_definitions.py b/specfile/macro_definitions.py index 68a4316..9f136c9 100644 --- a/specfile/macro_definitions.py +++ b/specfile/macro_definitions.py @@ -156,11 +156,7 @@ def get_raw_data(self) -> List[str]: elif self.comment_out_style is CommentOutStyle.HASH: sc = "#" macro = "global" if self.is_global else "define" - body = self.body.splitlines() - if body: - body[-1] += ws[3] - else: - body = [ws[3]] + body = (self.body + ws[3]).split("\n") result.append(f"{ws[0]}{dnl}{pre}{sc}{macro}{ws[1]}{self.name}{ws[2]}{body[0]}") result.extend(body[1:]) return result @@ -383,7 +379,7 @@ def count_brackets(s): line, _ = pop(lines) body += "\n" + line bc, pc = count_brackets(body) - tokens = re.split(r"(\s+)$", body, maxsplit=1) + tokens = re.split(r"([^\S\n]+)$", body, maxsplit=1) if len(tokens) == 1: body = tokens[0] else: diff --git a/specfile/sections.py b/specfile/sections.py index 1057e88..7b5ae98 100644 --- a/specfile/sections.py +++ b/specfile/sections.py @@ -268,7 +268,7 @@ def split_id(line): macro_definitions = MacroDefinitions.parse(lines) for md in macro_definitions: position = md.get_position(macro_definitions) - excluded_lines.append(range(position, position + len(md.body.splitlines()))) + excluded_lines.append(range(position, position + len(md.body.split("\n")))) section_id_regexes = [ re.compile(rf"^%{re.escape(n)}(\s+.*(?