DaanHoogland commented on code in PR #11327:
URL: https://github.com/apache/cloudstack/pull/11327#discussion_r2298191664


##########
server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java:
##########
@@ -1968,12 +1968,19 @@ protected Pair<String, String> 
getNextVmHostAndDisplayName(AutoScaleVmGroupVO as
                 RandomStringUtils.random(VM_HOSTNAME_RANDOM_SUFFIX_LENGTH, 0, 
0, true, false, (char[])null, new SecureRandom()).toLowerCase();
         // Truncate vm group name because max length of vm name is 63
         int subStringLength = Math.min(asGroup.getName().length(), 63 - 
VM_HOSTNAME_PREFIX.length() - vmHostNameSuffix.length());
-        String displayName = VM_HOSTNAME_PREFIX + 
asGroup.getName().substring(0, subStringLength) + vmHostNameSuffix;
-        String hostName = displayName;
-        if (isWindows) {
-            hostName = displayName.substring(Math.max(0, displayName.length() 
- 15));
+        String name = VM_HOSTNAME_PREFIX + asGroup.getName().substring(0, 
subStringLength) + vmHostNameSuffix;
+        if (!isWindows) {
+            return new Pair<>(name, name);
         }
-        return new Pair<>(hostName, displayName);
+        String hostName = name.substring(Math.max(0, name.length() - 15));
+        if (Character.isLetterOrDigit(hostName.charAt(0))) {
+            return new Pair<>(hostName, name);
+        }
+        String temp = name.substring(0, Math.max(0, name.length() - 
15)).replaceAll("[^a-zA-Z0-9]", "");

Review Comment:
   edge case: all of the last 15 chars are special chars or whitespace. I think 
we better do a replace first and then take the last 15.



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