leapp-repository/SOURCES/0045-repofileutils-disable-ConfigParser-interpolation-whe.patch
Yuriy Kohut 1a861d5b07 Rebase the ELevate Vendors patch based on the v0.24.0-3
Import from CS git

(cherry picked from commit 45c5f23f65)
2026-07-17 16:37:34 +03:00

73 lines
3.0 KiB
Diff

From 97bdaa4d90bdbb951de9d920036d93c08579bf2e Mon Sep 17 00:00:00 2001
From: Pradeep Jagtap <prjagtap@redhat.com>
Date: Fri, 17 Apr 2026 16:56:28 +0530
Subject: [PATCH 045/108] repofileutils: disable ConfigParser interpolation
when parsing .repo files
This occurs when parsing repository definitions containing percent-encoded
values (e.g. '%252B'in baseurls). Python's ConfigParser enables
interpolation by default and treats '%' as a special token, which causes
valid URLs to fail during parsing.
Disable interpolation by using parse_config(..., no_interpolation=True)
so that repository values are handled literally, consistent with DNF/YUM
behavior.
Jira-ref: RHEL-162328
---
.../common/libraries/repofileutils.py | 2 +-
repos/system_upgrade/common/libraries/utils.py | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/repos/system_upgrade/common/libraries/repofileutils.py b/repos/system_upgrade/common/libraries/repofileutils.py
index d8e087c1..4518b091 100644
--- a/repos/system_upgrade/common/libraries/repofileutils.py
+++ b/repos/system_upgrade/common/libraries/repofileutils.py
@@ -48,7 +48,7 @@ def parse_repofile(repofile):
"""
data = []
with open(repofile, mode='r') as fp:
- cp = utils.parse_config(fp, strict=False)
+ cp = utils.parse_config(fp, strict=False, no_interpolation=True)
for repoid in cp.sections():
try:
data.append(_parse_repository(repoid, dict(cp.items(repoid))))
diff --git a/repos/system_upgrade/common/libraries/utils.py b/repos/system_upgrade/common/libraries/utils.py
index b7aa9c74..bd5337c5 100644
--- a/repos/system_upgrade/common/libraries/utils.py
+++ b/repos/system_upgrade/common/libraries/utils.py
@@ -10,7 +10,7 @@ from leapp.libraries.stdlib import api, CalledProcessError, config, run, STDOUT
from leapp.utils.deprecation import deprecated
-def parse_config(cfg=None, strict=True):
+def parse_config(cfg=None, strict=True, no_interpolation=False):
"""
Applies a workaround to parse a config file using py3 AND py2
@@ -18,10 +18,20 @@ def parse_config(cfg=None, strict=True):
the old ones (Py2) obsoletes, these function was created to use the
ConfigParser on Py2 and Py3
+ When no_interpolation is True, values are read literally. Use this for
+ inputs that may contain percent-encoded URLs (e.g. yum .repo baseurl),
+ since default ConfigParser treats ``%`` as interpolation syntax.
+
:type cfg: str
:type strict: bool
+ :type no_interpolation: bool
"""
- if six.PY3:
+ if no_interpolation:
+ if six.PY3:
+ parser = six.moves.configparser.RawConfigParser(strict=strict) # pylint: disable=unexpected-keyword-arg
+ else:
+ parser = six.moves.configparser.RawConfigParser()
+ elif six.PY3:
parser = six.moves.configparser.ConfigParser(strict=strict) # pylint: disable=unexpected-keyword-arg
else:
parser = six.moves.configparser.ConfigParser()
--
2.54.0