Skip to content

Render unnamed flag bits in flags.to_text() instead of dropping them - #1276

Merged
rthalley merged 1 commit into
rthalley:mainfrom
eugen-goebel:flags-render-unknown-bits
Jun 27, 2026
Merged

rthalley merged 1 commit into
rthalley:mainfrom
eugen-goebel:flags-render-unknown-bits

Conversation

@eugen-goebel

Copy link
Copy Markdown
Contributor

Closes #1264.

dns.flags.to_text() and dns.flags.edns_to_text() only iterated the named enum members, so any set bit without a named flag was silently dropped. For example, edns_to_text(0x2000) returned '' and edns_to_text(DO | 0x2000) returned 'DO', hiding the unknown bit.

Unnamed bits are now rendered as FLAGn, where n is the bit position, and from_text() / edns_from_text() parse that form back, so the conversions round-trip:

>>> dns.flags.edns_to_text(0x2000)
'FLAG13'
>>> dns.flags.edns_to_text(dns.flags.DO | 0x2000)
'DO FLAG13'
>>> dns.flags.edns_from_text('DO FLAG13') == (dns.flags.DO | 0x2000)
True

This mirrors how dnspython already renders other unknown protocol values (e.g. TYPEnnnn for unknown RR types). Tests are added in tests/test_flags.py and a whatsnew entry is included.

A small design note: I went with FLAGn (bit position) for the token. Happy to switch to another representation if you would prefer one, since you mentioned wanting to ponder the format.

Closes rthalley#1264.

dns.flags.to_text() and dns.flags.edns_to_text() iterated only the named
enum members, so any set bit without a named flag (for example the EDNS
0x2000 bit) was silently dropped from the text representation. Such bits
are now rendered as FLAGn, where n is the bit position, and from_text()
and edns_from_text() parse that form back, so the conversions round-trip.

Adds tests in tests/test_flags.py and a whatsnew entry.
@rthalley
rthalley merged commit 715fb88 into rthalley:main Jun 27, 2026
@rthalley

Copy link
Copy Markdown
Owner

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flags.edns_to_text() ignores unknown flags

2 participants