stoty commented on code in PR #6456:
URL: https://github.com/apache/hbase/pull/6456#discussion_r2282963500


##########
hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java:
##########
@@ -62,6 +65,12 @@ public class ServerName implements Comparable<ServerName>, 
Serializable {
    */
   private static final short VERSION = 0;
   static final byte[] VERSION_BYTES = Bytes.toBytes(VERSION);
+  private static final String COLON_ENCODED_VALUE = "%3a";
+
+  public static final String COLON = ":";
+
+  // IPV6 address length separated by COLON(:), eg: 
"0:0:0:0:0:0:0:1".split(colon).length
+  private static final int IPV6_SPLIT_COLON_LENGTH = 8;

Review Comment:
   What about shorthand addresses ? i.e. 1:2::5:6



##########
hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java:
##########
@@ -327,7 +336,49 @@ public static ServerName parseVersionedServerName(final 
byte[] versionedBytes) {
    * @return A ServerName instance.
    */
   public static ServerName parseServerName(final String str) {
-    return SERVERNAME_PATTERN.matcher(str).matches() ? valueOf(str) : 
valueOf(str, NON_STARTCODE);
+    ServerName sn =
+      SERVERNAME_PATTERN.matcher(str).matches() ? valueOf(str) : valueOf(str, 
NON_STARTCODE);
+    String hostname = sn.getHostname();
+    // if IPV6 address is in encoded format, need to check and validate its 
address length
+    // eg: if address is like 
"0%3a0%3a0%3a0%3a0%3a0%3a0%3a0%3a1,16020,1720673488765" decode to
+    // "0:0:0:0:0:0:0:1,16020,1720673488765"
+    if (isIpv6ServerName(hostname, COLON_ENCODED_VALUE)) {
+      try {
+        hostname = URLDecoder.decode(sn.getHostname(), "UTF8");
+        return ServerName.valueOf(hostname, sn.getPort(), sn.getStartCode());
+      } catch (UnsupportedEncodingException e) {
+        throw new IllegalArgumentException("Exception occurred while decoding 
server name", e);
+      }
+    }
+    return sn;
+  }
+
+  /**
+   * Verify the ServerAddress is in IPV6 format or not
+   * @param serverAddress    IP address
+   * @param addressSeparator IPV6 address separator
+   * @return true if server address is in IPV6 format
+   */
+  public static boolean isIpv6ServerName(String serverAddress, String 
addressSeparator) {
+    return serverAddress.contains(addressSeparator)

Review Comment:
   Generally, we should try and use the standard library network functions as 
much as possible to parse IP addresses instead of trying to match the format.
   i.e. just perform any necessary decoding, then attempt to parse it into an 
Address.



-- 
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