Skip to content

Commit 5d7b048

Browse files
committed
gh-155836: Fix IPv6Address.reverse_pointer for addresses with a scope id
_reverse_pointer derives from self.exploded, which since gh-88178 carries the %scope_id suffix. Strip the scope id before building the pointer so it is not spliced into the reversed nibbles.
1 parent c92e2fd commit 5d7b048

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lib/ipaddress.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,11 @@ def _reverse_pointer(self):
19301930
This implements the method described in RFC3596 2.5.
19311931
19321932
"""
1933-
reverse_chars = self.exploded[::-1].replace(':', '')
1933+
exploded = self.exploded
1934+
scope_id = getattr(self, '_scope_id', None)
1935+
if scope_id:
1936+
exploded = exploded.replace('%' + scope_id, '', 1)
1937+
reverse_chars = exploded[::-1].replace(':', '')
19341938
return '.'.join(reverse_chars) + '.ip6.arpa'
19351939

19361940
@staticmethod

Lib/test/test_ipaddress.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,14 @@ def testReversePointer(self):
27632763
'2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.'
27642764
'ip6.arpa'
27652765
)
2766+
),
2767+
# a scope id is not part of the pointer name
2768+
(
2769+
'fe80::1%eth0', (
2770+
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
2771+
'0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.'
2772+
'ip6.arpa'
2773+
)
27662774
)
27672775
]:
27682776
with self.subTest('ipv6_reverse_pointer', addr=addr_v6):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :attr:`ipaddress.IPv6Address.reverse_pointer` returning an invalid name
2+
for an address carrying a scope id; the scope id is no longer spliced into the
3+
reverse DNS pointer.

0 commit comments

Comments
 (0)