Repository navigation
Conversation
johnpryan
commented
Dec 2, 2026
- Update isLoopbackHost to use web-safe Uri.parseIPv4Address and Uri.parseIPv6Address (supporting localhost, 127.0.0.0/8, and canonical/expanded IPv6 ::1).
- Remove the duplicate _isLoopbackHost helper in ServerApi and delegate to isLoopbackHost.
- Add unit tests for isLoopbackHost in service_utils_test.dart.
- Update isLoopbackHost to use web-safe Uri.parseIPv4Address and Uri.parseIPv6Address (supporting localhost, 127.0.0.0/8, and canonical/expanded IPv6 ::1). - Remove the duplicate _isLoopbackHost helper in ServerApi and delegate to isLoopbackHost. - Add unit tests for isLoopbackHost in service_utils_test.dart.
There was a problem hiding this comment.
Code Review
This pull request refactors the isLoopbackHost utility in packages/devtools_shared to be web-safe by removing dart:io dependencies and utilizing Uri.parseIPv4Address and Uri.parseIPv6Address. The ServerApi class has been updated to use this refactored utility, and comprehensive unit tests have been added to verify the loopback host logic. A review comment suggests using ListEquality for IPv6 byte comparison to improve code readability and maintain consistency with existing patterns.
| for (var i = 0; i < 15; i++) { | ||
| if (bytes[i] != 0) return false; | ||
| } | ||
| return bytes[15] == 1; |
There was a problem hiding this comment.
[CONCERN] To improve readability, avoid magic numbers, and maintain consistency with how IP address bytes are compared elsewhere in the codebase (e.g., ServerApi._hostsMatch using ListEquality), we can compare the parsed IPv6 bytes directly to the expected loopback byte array using ListEquality from package:collection.
const ipv6LoopbackBytes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
return const ListEquality<int>().equals(bytes, ipv6LoopbackBytes);References
- Adhering to consistent style across all DevTools packages improves collaboration and reduces errors. Avoid using raw/magic strings or numbers. Extract them into descriptive named constants so the intent and meaning of the values are clear. (link)