Fix Pacman regex for unmatched Arch package name (#48558)

* Fix Pacman regex for unmatched Arch package name

`ansible -m pacman -a upgrade=yes $(hostname)` failed due to not
accounting for the `+` character in the `pacman -Qu` output line:

    libsigc++ 2.10.0-1 -> 2.10.1-1

Per the Arch wiki¹, package names can contain alphanumeric characters,
and any of {`@`, `.`, `_`, `+`, `-`}.

The existing `re` covered `_` (part of `\w` in Python), and `-`
(explicitly included). This change adds `@`, `.`, and `+` (in
ASCII-betical order).

¹: https://wiki.archlinux.org/index.php/Arch_package_guidelines#Package_naming

* Add explanation for `pacman -Qu` regex matching

* Remove unneeded non-capturing groups in regex
pull/58895/head
Benjamin R. Haskell 5 years ago committed by ansibot
parent b9dafdbade
commit 73a7a0877d

@ -230,7 +230,10 @@ def upgrade(module, pacman_path):
}
if rc == 0:
regex = re.compile(r'([\w-]+) ((?:\S+)-(?:\S+)) -> ((?:\S+)-(?:\S+))')
# Match lines of `pacman -Qu` output of the form:
# (package name) (before version-release) -> (after version-release)
# e.g., "ansible 2.7.1-1 -> 2.7.2-1"
regex = re.compile(r'([\w+\-.@]+) (\S+-\S+) -> (\S+-\S+)')
for p in data:
m = regex.search(p)
packages.append(m.group(1))

Loading…
Cancel
Save