Skip to content

fix(regex): IP_Address truncates the last octet of IP addresses - #107

Open
0xABCD01 wants to merge 1 commit into
dwisiswant0:masterfrom
0xABCD01:fix/ip-address-80
Open

0xABCD01 wants to merge 1 commit into
dwisiswant0:masterfrom
0xABCD01:fix/ip-address-80

Conversation

@0xABCD01

@0xABCD01 0xABCD01 commented Nov 4, 2026

Copy link
Copy Markdown

Fixes #80

The IP_Address pattern lists the single-digit alternative [0-9]
first in each octet. Python's re alternation is first-match, so the
last octet always stops after one digit: a source line containing
http://172.31.2.51:600 is reported as 172.31.2.5, and 172.31.2.54
collapses into the same wrong result.

This reorders the octet alternation longest-first
(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9]) and guards both ends
against digit/dot continuation, so the pattern matches a complete IPv4
address and no longer returns a fragment of a longer dotted token.
Tokens with an invalid octet now report nothing instead of a
fabricated fragment: previously 999.1.2.3 was reported as
99.1.2.3, 256.1.1.1 as 56.1.1.1, and 1.2.3.456 as 1.2.3.4.
The same applies to octets with leading zeros (010.1.2.3,
1.2.3.04), which the old pattern reported as fragments and the new
one does not report. Addresses followed by a port or by sentence
punctuation still match.

Verified with a line battery run through the same compile+search
semantics as util.finder(), plus an end-to-end util.finder() run
over a sample decompiled tree: before, it returned ['172.31.2.5'];
after, it returns ['172.31.2.51', '172.31.2.54']. All 53 patterns in
regexes.json still compile.

…ddresses

Reorder the octet alternation longest-first so a full IPv4 address is
matched, and guard both ends against digit/dot continuation so the
pattern no longer reports a fragment of a longer dotted token
(e.g. 172.31.2.51 was reported as 172.31.2.5).

Fixes dwisiswant0#80
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.

The obtained IP address is incomplete

1 participant