Skip to content

IPv6Address.exploded raises AddressValueError for valid scoped addresses #158728

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The inherited exploded property in _IPAddressBase promises: "Return the longhand version of the IP address as a string." The IPv6Address documentation permits a scope zone ID appended using '%', giving 'ff02::1234%1' as an example.

Expected: fe80:0000:0000:0000:0000:0000:0000:0001%a

Actual: AddressValueError: Only hex digits permitted in '1%a' in 'fe80::1%a'

import ipaddress

s = 'fe80::1%' + 'a'
try:
    zone = s.split('%')[1]
    if not zone or not zone.isascii() or not zone.isalpha():
        raise ValueError('scope is not nonempty ASCII alphabetic')
    a = ipaddress.IPv6Address(s)
    n = 0xfe800000000000000000000000000001
    if a.scope_id != zone or int(a) != n:
        raise ValueError('input did not parse as the documented scoped address')
except Exception as e:
    print('REFUTATION REJECTED:', str(e))
else:
    expected = ':'.join(f'{(n >> i) & 65535:04x}' for i in range(112, -1, -16)) + '%' + zone
    try:
        actual = a.exploded
    except Exception as e:
        actual = (type(e).__name__, str(e))
    if actual != expected:
        print('REFUTATION CONFIRMED:', repr(s), 'actual =', repr(actual), 'expected =', repr(expected))
    else:
        print('REFUTATION REJECTED: exploded matches the documented expectation')

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library ipaddress:

REFUTATION CONFIRMED: 'fe80::1%a' actual = ('AddressValueError', "Only hex digits permitted in '1%a' in 'fe80::1%a'") expected = 'fe80:0000:0000:0000:0000:0000:0000:0001%a'

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/ipaddress-c1

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions