From: Jörg Behrmann Date: Wed, 24 Sep 2025 10:04:03 +0000 (+0200) Subject: Add ASCII flag to regexes using backslash character classes X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f4ec578986ebb95a48befb43fc5f5132fbc39870;p=thirdparty%2Fmkosi.git Add ASCII flag to regexes using backslash character classes By default Python regexes like strings are unicode meaning that they match anything unicode consides, e.g. a number in the case of \d, which is more than the usually expected [0-9]. Tighten this in the places where these classes are used for better readability. Also reorder the character classes for KERNEL_VERSION_PATTERN and the systemd-stub version to be the same order for clarity and escape the dash in the latter, since the need to escape a dash in a character range is position dependent. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 24ebd8731..638a4c801 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -171,7 +171,7 @@ from mkosi.versioncomp import GenericVersion from mkosi.vmspawn import run_vmspawn # Allowed characters from https://uapi-group.org/specifications/specs/version_format_specification -KERNEL_VERSION_PATTERN = re.compile(r"\d+\.\d+[\w.\-~^+]*") +KERNEL_VERSION_PATTERN = re.compile(r"\d+\.\d+[\w\-.~^+]*", re.ASCII) @contextlib.contextmanager @@ -1930,7 +1930,7 @@ def systemd_stub_version(context: Context, stub: Path) -> Optional[GenericVersio if not ( version := re.match( - r"#### LoaderInfo: systemd-stub (?P[.~^a-zA-Z0-9-+_]+) ####", sdmagic_text + r"#### LoaderInfo: systemd-stub (?P[\w\-.~^+]+) ####", sdmagic_text, re.ASCII ) ): die(f"Unable to determine systemd-stub version, found {sdmagic_text!r}") diff --git a/mkosi/distributions/fedora.py b/mkosi/distributions/fedora.py index 598b06e9d..c01b54fd2 100644 --- a/mkosi/distributions/fedora.py +++ b/mkosi/distributions/fedora.py @@ -39,7 +39,7 @@ def read_remote_rawhide_key_symlink(context: Context) -> str: @tuplify def find_fedora_rpm_gpgkeys(context: Context) -> Iterable[str]: - versionre = re.compile(r"RPM-GPG-KEY-fedora-(\d+)-primary") + versionre = re.compile(r"RPM-GPG-KEY-fedora-(\d+)-primary", re.ASCII) # ELN uses the rawhide GPG keys. release = "rawhide" if context.config.release == "eln" else context.config.release