Skip to content

Commit 9eb0afc

Browse files
tonghuarootasvetlov
authored andcommitted
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 828c153 commit 9eb0afc

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
@@ -1978,7 +1978,11 @@ def _reverse_pointer(self):
19781978
This implements the method described in RFC3596 2.5.
19791979
19801980
"""
1981-
reverse_chars = self.exploded[::-1].replace(':', '')
1981+
exploded = self.exploded
1982+
scope_id = getattr(self, '_scope_id', None)
1983+
if scope_id:
1984+
exploded = exploded.replace('%' + scope_id, '', 1)
1985+
reverse_chars = exploded[::-1].replace(':', '')
19821986
return '.'.join(reverse_chars) + '.ip6.arpa'
19831987

19841988
@staticmethod

‎Lib/test/test_ipaddress.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,6 +2850,14 @@ def testReversePointer(self):
28502850
'2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.'
28512851
'ip6.arpa'
28522852
)
2853+
),
2854+
# a scope id is not part of the pointer name
2855+
(
2856+
'fe80::1%eth0', (
2857+
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
2858+
'0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.'
2859+
'ip6.arpa'
2860+
)
28532861
)
28542862
]:
28552863
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)