Skip to content

Commit 7b3cd65

Browse files
committed
Convert also shell expansions doing string processing on constants
For instance `%(echo 1.27.9-rc1 | sed 's/-/~/g')`. Signed-off-by: Nikola Forró <nforro@redhat.com> Assisted-by: Claude Opus 4.6 via Cursor
1 parent c0061d8 commit 7b3cd65

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

specfile/sanitizer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ def normalize_macro(expr):
359359
return None
360360
return expr
361361

362+
def normalize_literal(expr):
363+
expr = strip_quotes(expr.strip())
364+
if not expr or re.search(r"[%{}]", expr):
365+
return None
366+
return f"%{{quote:{expr}}}"
367+
362368
def is_safe_for_expand(s):
363369
return not re.search(r"%(\{\w+[\s:]|\(|\[)", s)
364370

@@ -709,7 +715,7 @@ def convert_glob_removal(expr, op, pat):
709715
# --- echo EXPR | CMD (pipe pattern) ---
710716
m = _RE_PIPE.match(body)
711717
if m:
712-
expr = normalize_macro(m.group(1))
718+
expr = normalize_macro(m.group(1)) or normalize_literal(m.group(1))
713719
if expr is not None:
714720
cmd = m.group(2).strip()
715721
result = convert_string_op(expr, cmd)
@@ -720,7 +726,7 @@ def convert_glob_removal(expr, op, pat):
720726
m = _RE_HERESTRING.match(body)
721727
if m:
722728
cmd = m.group(1).strip()
723-
expr = normalize_macro(m.group(2))
729+
expr = normalize_macro(m.group(2)) or normalize_literal(m.group(2))
724730
if expr is not None:
725731
result = convert_string_op(expr, cmd)
726732
if result:

0 commit comments

Comments
 (0)