From 58a7c7fdbe328e2f0db15b47ef09624e53967881 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 17 May 2026 10:31:08 +0200 Subject: [PATCH] [PR #12064/9cba458e backport][stable-11] cargo: fix version parsing when `state=latest` (#12068) 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 (cherry picked from commit 9cba458e3e8fe7d7deea63ff36c4b1e57dcdb72a) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- 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 c00983fade..19b259d4a0 100644 --- a/plugins/modules/cargo.py +++ b/plugins/modules/cargo.py @@ -209,7 +209,7 @@ class Cargo(object): 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="No published version for package %s found" % name