Files
nip/testhelper
Brian Cunnie 432e836c15 🐞 IPv4 regex correctly identifies IPv4 addresses.
My regex was broken, and it didn't correctly identify the following
hostnames lookups (real, actual hostname lookups):

- funprdmongo30-03.10.1.4.133.nip.io.
- olvm-engine-01.132.145.157.105.nip.io.
- wt32-ETh01-03.172.26.131.29.NIp.IO.

The problem? The leading zero. `funprdmongo30-03.10.1.4.133.nip.io.`
should've resolved to `10.1.4.133`, but the regex incorrectly matched it
as `03.10.1.4`, which isn't a valid IPv4 address according to Golang's
net library, so the hostname DNS resolution was incorrectly treated as
not having an A record.

With this commit, the regex is now fixed, though I must admit I have a
certain trepidation tinkering with the regex at the very core of
sslip.io.

- refactored a portion of the `NameToA()` function to another function,
  `String2IPv4()`. `NameToA()` is now more readable.
- added simple fuzz test, but it wouldn't have discovered the problem.
- added a helper method for the fuzz test, `RandomIPv4String()`, and
  bumped `math/rand` to `math/rand/v2` along the way.
2025-08-30 18:40:21 -07:00
..