From 56bd860a5eb39543f838ab2e62bec0d424e907d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar=20Su=C3=A1stegui?= Date: Mon, 30 Mar 2026 03:07:11 -0600 Subject: [PATCH] fix: use [2:] instead of lstrip('0x') to strip hex prefix in ifconfig parser str.lstrip('0x') strips any combination of '0' and 'x' characters from the left, not the literal two-character prefix '0x'. For subnet masks where the hex digits start with '0' (e.g. '0x00000000' for a /0 mask), lstrip strips all leading zeros along with the 'x', producing an empty string instead of '00000000'. Replace with a slice [2:] which correctly removes exactly the first two characters ('0x') regardless of what follows. This bug affected both the legacy ipv4_mask field and the ipv4[] list items in _process() (lines 267 and 292). Fixes #685 --- jc/parsers/ifconfig.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index 021f5026..23d67fdc 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -264,7 +264,7 @@ def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]: try: if entry['ipv4_mask'].startswith('0x'): new_mask = entry['ipv4_mask'] - new_mask = new_mask.lstrip('0x') + new_mask = new_mask[2:] new_mask = '.'.join(str(int(i, 16)) for i in [new_mask[i:i + 2] for i in range(0, len(new_mask), 2)]) entry['ipv4_mask'] = new_mask except (ValueError, TypeError, AttributeError): @@ -289,7 +289,7 @@ def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]: try: if ip_address['mask'].startswith('0x'): new_mask = ip_address['mask'] - new_mask = new_mask.lstrip('0x') + new_mask = new_mask[2:] new_mask = '.'.join(str(int(i, 16)) for i in [new_mask[i:i + 2] for i in range(0, len(new_mask), 2)]) ip_address['mask'] = new_mask except (ValueError, TypeError, AttributeError):