From 9cdd6e58b339317cc3dd17b0d5919eb6ee49f722 Mon Sep 17 00:00:00 2001 From: spyinx <166288294+spyinx@users.noreply.github.com> Date: Wed, 6 Nov 2024 00:05:21 +0800 Subject: Fixed ipv6 pattern in parse_address (#84237) --- changelogs/fragments/fix-ipv6-pattern.yml | 2 ++ lib/ansible/parsing/utils/addresses.py | 4 ++-- test/units/parsing/utils/test_addresses.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix-ipv6-pattern.yml diff --git a/changelogs/fragments/fix-ipv6-pattern.yml b/changelogs/fragments/fix-ipv6-pattern.yml new file mode 100644 index 0000000000..48b1815052 --- /dev/null +++ b/changelogs/fragments/fix-ipv6-pattern.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix ipv6 pattern bug in lib/ansible/parsing/utils/addresses.py (https://github.com/ansible/ansible/issues/84237) \ No newline at end of file diff --git a/lib/ansible/parsing/utils/addresses.py b/lib/ansible/parsing/utils/addresses.py index 33982d0485..5485c5f668 100644 --- a/lib/ansible/parsing/utils/addresses.py +++ b/lib/ansible/parsing/utils/addresses.py @@ -126,7 +126,7 @@ patterns = { 'ipv6': re.compile( r"""^ - (?:{0}:){{7}}{0}| # uncompressed: 1:2:3:4:5:6:7:8 + ((?:{0}:){{7}}{0}| # uncompressed: 1:2:3:4:5:6:7:8 (?:{0}:){{1,6}}:| # compressed variants, which are all (?:{0}:)(?::{0}){{1,6}}| # a::b for various lengths of a,b (?:{0}:){{2}}(?::{0}){{1,5}}| @@ -139,7 +139,7 @@ patterns = { # ipv4-in-ipv6 variants (?:0:){{6}}(?:{0}\.){{3}}{0}| ::(?:ffff:)?(?:{0}\.){{3}}{0}| - (?:0:){{5}}ffff:(?:{0}\.){{3}}{0} + (?:0:){{5}}ffff:(?:{0}\.){{3}}{0}) $ """.format(ipv6_component), re.X | re.I ), diff --git a/test/units/parsing/utils/test_addresses.py b/test/units/parsing/utils/test_addresses.py index 7562940dd8..4f94c8ab2c 100644 --- a/test/units/parsing/utils/test_addresses.py +++ b/test/units/parsing/utils/test_addresses.py @@ -34,6 +34,8 @@ class TestParseAddress(unittest.TestCase): '::ffff:1.2.3.4': ['::ffff:1.2.3.4', None], '::1.2.3.4': ['::1.2.3.4', None], '1234::': ['1234::', None], + # Invalid IPv6 address + '1234::9abc:def0:1234:5678:9abc::::::::def0': [None, None], # Hostnames 'some-host': ['some-host', None], -- cgit v1.2.3