From 745b8f16a85e97f0797b700c6671448023d48e68 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Mon, 25 Jul 2022 19:56:07 +0100 Subject: [PATCH] fix: only parse the digits from the pg version (#315) --- plugins/modules/postgresql_info.py | 11 ++++++----- plugins/modules/postgresql_ping.py | 12 +++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/modules/postgresql_info.py b/plugins/modules/postgresql_info.py index 5ac10a848..15886701d 100644 --- a/plugins/modules/postgresql_info.py +++ b/plugins/modules/postgresql_info.py @@ -506,6 +506,7 @@ sample: false ''' +import re from fnmatch import fnmatch try: @@ -959,13 +960,13 @@ def get_pg_version(self): query = "SELECT version()" raw = self.__exec_sql(query)[0][0] full = raw.split()[1] - tmp = full.split('.') + m = re.match(r"(\d+)\.(\d+)(\.(\d+))?", full) - major = int(tmp[0]) - minor = int(tmp[1].rstrip(',')) + major = int(m[1]) + minor = int(m[2]) patch = None - if len(tmp) >= 3: - patch = int(tmp[2].rstrip(',')) + if m[3] is not None: + patch = int(m[3]) self.pg_info["version"] = dict( major=major, diff --git a/plugins/modules/postgresql_ping.py b/plugins/modules/postgresql_ping.py index 53f324cf0..af18c5326 100644 --- a/plugins/modules/postgresql_ping.py +++ b/plugins/modules/postgresql_ping.py @@ -91,6 +91,8 @@ version_added: 1.7.0 ''' +import re + try: from psycopg2.extras import DictCursor except ImportError: @@ -137,13 +139,13 @@ def get_pg_version(self): self.is_available = True full = raw.split()[1] - tmp = full.split('.') + m = re.match(r"(\d+)\.(\d+)(\.(\d+))?", full) - major = int(tmp[0]) - minor = int(tmp[1].rstrip(',')) + major = int(m[1]) + minor = int(m[2]) patch = None - if len(tmp) >= 3: - patch = int(tmp[2].rstrip(',')) + if m[3] is not None: + patch = int(m[3]) self.version = dict( major=major,