From 9cba458e3e8fe7d7deea63ff36c4b1e57dcdb72a Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sun, 17 May 2026 20:24:03 +1200 Subject: [PATCH] cargo: fix version parsing when `state=latest` (#12064) * fix(cargo): fix greedy regex in get_latest_published_version Fixes #8949 * docs(cargo): add changelog fragment for #12064 --- changelogs/fragments/12064-cargo-latest-version-regex.yml | 4 ++++ plugins/modules/cargo.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/12064-cargo-latest-version-regex.yml diff --git a/changelogs/fragments/12064-cargo-latest-version-regex.yml b/changelogs/fragments/12064-cargo-latest-version-regex.yml new file mode 100644 index 0000000000..cfc548224f --- /dev/null +++ b/changelogs/fragments/12064-cargo-latest-version-regex.yml @@ -0,0 +1,4 @@ +bugfixes: + - "cargo - fix ``state=latest`` always reporting ``changed`` due to greedy regex capturing description text instead of version string + (https://github.com/ansible-collections/community.general/issues/8949, + https://github.com/ansible-collections/community.general/pull/12064)." diff --git a/plugins/modules/cargo.py b/plugins/modules/cargo.py index 68c8ad4f55..98c885908c 100644 --- a/plugins/modules/cargo.py +++ b/plugins/modules/cargo.py @@ -196,7 +196,7 @@ class Cargo: cmd = ["search", name, "--limit", "1"] data, dummy = self._exec(cmd, True, False, False) - match = re.search(r'"(.+)"', data) + match = re.search(r"^" + re.escape(name) + r'\s*=\s*"([^"]+)"', data, re.MULTILINE) if not match: self.module.fail_json(msg=f"No published version for package {name} found") return match.group(1)