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