godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.38k stars 21.26k forks source link

Fix `is_valid_ip_address()` to handle incorrect paddings #99624

Open MarcusPaulsson opened 1 day ago

MarcusPaulsson commented 1 day ago

Proposal to Fix Inconsistent Behavior in is_valid_ip_address() for IPv6 Addresses with Multiple :: Fixes: #99623

This pull request resolves inconsistent behavior in the is_valid_ip_address() method when validating IPv6 addresses. Specifically, it addresses the following issues:

Old behavior:

issue_image

New behavior:

fixed_issue_image

The updated is_valid_ip_address() method tracks :: with double_colon_index, ensuring only one occurrence. It validates segment counts, handles compressed zeros logically, and strictly enforces IPv4-mapped segments in the final position.

RedMser commented 1 day ago

This seems like a good opportunity to bring your test suite into the unit tests of the engine: https://github.com/godotengine/godot/blob/0c45ace151f25de2ca54fe7a46b6f077be32ba6f/tests/core/string/test_string.h

Should likely be done as a separate PR after this one.