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.
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
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}")
@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