Copilot commented on code in PR #18162:
URL: https://github.com/apache/iotdb/pull/18162#discussion_r3549835547


##########
iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/UrlUtils.java:
##########
@@ -21,33 +21,93 @@
 
 import org.apache.iotdb.common.rpc.thrift.TEndPoint;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 /** The UrlUtils */
 public class UrlUtils {
   private static final String PORT_SEPARATOR = ":";
-  private static final String ABB_COLON = "[";
+  private static final String IPV6_BEGIN_MARK = "[";
+  private static final String IPV6_END_MARK = "]";
 
   private UrlUtils() {}
 
   /**
    * Parse TEndPoint from a given TEndPointUrl
    * example:[D80:0000:0000:0000:ABAA:0000:00C2:0002]:22227
    *
-   * @param endPointUrl ip:port
+   * @param endPointUrl host:port or [ipv6]:port
    * @return TEndPoint null if parse error
    */

Review Comment:
   Javadoc is inconsistent with the current behavior: 
`parseTEndPointIpv4AndIpv6Url` never returns `null` on parse error and can 
throw `NumberFormatException` for malformed bracketed inputs. This can mislead 
callers about error handling expectations.



##########
iotdb-core/ainode/iotdb/ainode/core/config.py:
##########
@@ -466,13 +466,22 @@ def load_properties(filepath, sep="=", comment_char="#"):
 def parse_endpoint_url(endpoint_url: str) -> TEndPoint:
     """Parse TEndPoint from a given endpoint url.
     Args:
-        endpoint_url: an endpoint url, format: ip:port
+        endpoint_url: an endpoint url, format: host:port or [ipv6]:port
     Returns:
         TEndPoint
     Raises:
-        BadNodeUrlError
+        BadNodeUrlException
     """
-    split = endpoint_url.split(":")
+    if endpoint_url.startswith("["):
+        end_index = endpoint_url.find("]")
+        if end_index == -1 or end_index + 1 >= len(endpoint_url):
+            raise BadNodeUrlException(endpoint_url)

Review Comment:
   Bracketed endpoint parsing currently accepts empty IPv6 literals like 
`[]:123` because it only checks `end_index == -1`. This should be rejected 
(host must be non-empty) to match the intended `[ipv6]:port` format and the 
stricter checks used in other client parsers.



##########
iotdb-core/ainode/iotdb/ainode/core/config.py:
##########
@@ -466,13 +466,22 @@ def load_properties(filepath, sep="=", comment_char="#"):
 def parse_endpoint_url(endpoint_url: str) -> TEndPoint:
     """Parse TEndPoint from a given endpoint url.
     Args:
-        endpoint_url: an endpoint url, format: ip:port
+        endpoint_url: an endpoint url, format: host:port or [ipv6]:port
     Returns:
         TEndPoint
     Raises:
-        BadNodeUrlError
+        BadNodeUrlException
     """
-    split = endpoint_url.split(":")
+    if endpoint_url.startswith("["):
+        end_index = endpoint_url.find("]")
+        if end_index == -1 or end_index + 1 >= len(endpoint_url):
+            raise BadNodeUrlException(endpoint_url)
+        if endpoint_url[end_index + 1] != ":":
+            raise BadNodeUrlException(endpoint_url)
+        split = [endpoint_url[1:end_index], endpoint_url[end_index + 2 :]]
+    else:
+        split = endpoint_url.rsplit(":", 1)

Review Comment:
   Non-bracketed parsing falls back to `rsplit(':', 1)` even when the input 
contains stray `[`/`]` characters (e.g. `foo[::1]:6667`), which is neither a 
valid `host:port` nor `[ipv6]:port` endpoint. This should be rejected to avoid 
silently accepting malformed inputs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to