]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add ASCII flag to regexes using backslash character classes
authorJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 24 Sep 2025 10:04:03 +0000 (12:04 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 24 Sep 2025 10:42:01 +0000 (12:42 +0200)
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.

mkosi/__init__.py
mkosi/distributions/fedora.py

index 24ebd87318279872e7aec670f768991e878ce6f8..638a4c801c8d639c3f8d81991deb6a0ac33b38b3 100644 (file)
@@ -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<version>[.~^a-zA-Z0-9-+_]+) ####", sdmagic_text
+            r"#### LoaderInfo: systemd-stub (?P<version>[\w\-.~^+]+) ####", sdmagic_text, re.ASCII
         )
     ):
         die(f"Unable to determine systemd-stub version, found {sdmagic_text!r}")
index 598b06e9dd37b8d91ec798918b24e890b946533d..c01b54fd20e3a360334078b6b63cec09e4ac15d0 100644 (file)
@@ -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