gem: Fix get_installed_versions: correctly parse "default" version. (#783)
* Fix get_installed_versions: correctly parse "default" version. gem query output of bundler (default: 2.1.4, 1.17.2) Gets parsed as: ['default:', '1.17.2'] Fix this by skipping "default: " if present in the list of versions - by adding it as an optional part of the regex, grouped as a non-capturing group to keep the index of existing group. This now correctly parses the above input as ['2.1.4:', '1.17.2'] Fixes #782 * Fix gem get_installed_versions (cont): add changelog fragment * Update changelogs/fragments/783-fix-gem-installed-versions.yaml as per suggestion Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>pull/849/head
parent
8f2b2d9dc6
commit
6dc98c08fd
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "gem - fix get_installed_versions: correctly parse ``default`` version (https://github.com/ansible-collections/community.general/pull/783)."
|
|
@ -157,7 +157,7 @@ def get_installed_versions(module, remote=False):
|
||||||
(rc, out, err) = module.run_command(cmd, environ_update=environ, check_rc=True)
|
(rc, out, err) = module.run_command(cmd, environ_update=environ, check_rc=True)
|
||||||
installed_versions = []
|
installed_versions = []
|
||||||
for line in out.splitlines():
|
for line in out.splitlines():
|
||||||
match = re.match(r"\S+\s+\((.+)\)", line)
|
match = re.match(r"\S+\s+\((?:default: )?(.+)\)", line)
|
||||||
if match:
|
if match:
|
||||||
versions = match.group(1)
|
versions = match.group(1)
|
||||||
for version in versions.split(', '):
|
for version in versions.split(', '):
|
||||||
|
|
Loading…
Reference in New Issue