Copilot commented on code in PR #12078:
URL: https://github.com/apache/cloudstack/pull/12078#discussion_r2526203599


##########
server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManagerImpl.java:
##########
@@ -179,10 +180,14 @@ public void setResetTokenAndSend(UserAccount userAccount) 
{
         final String email = userAccount.getEmail();
         final String username = userAccount.getUsername();
         final String subject = "Password Reset Request";
-        final String domainUrl = UserPasswordResetDomainURL.value();
+        String domainUrl = UserPasswordResetDomainURL.value();
+        if (StringUtils.isBlank(domainUrl)) {
+            domainUrl = ManagementServerAddresses.value().split(",")[0];

Review Comment:
   Potential issues with array access and whitespace handling. If 
ManagementServerAddresses.value() returns an empty string or the split result 
contains whitespace, this could cause problems. Consider adding validation and 
trimming whitespace similar to how it's handled in 
IndirectAgentLBServiceImpl.java (line 115): 
`ManagementServerAddresses.value().replace(\" \", \"\").split(\",\")[0]` or add 
explicit validation before splitting.
   ```suggestion
               String mgmtAddresses = ManagementServerAddresses.value();
               if (!StringUtils.isBlank(mgmtAddresses)) {
                   String[] addresses = mgmtAddresses.replace(" ", 
"").split(",");
                   if (addresses.length > 0 && 
!StringUtils.isBlank(addresses[0])) {
                       domainUrl = addresses[0];
                   } else {
                       logger.warn("ManagementServerAddresses config is empty 
or invalid, cannot set domainUrl.");
                       domainUrl = "";
                   }
               } else {
                   logger.warn("ManagementServerAddresses config is blank, 
cannot set domainUrl.");
                   domainUrl = "";
               }
   ```



##########
server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManagerImpl.java:
##########
@@ -179,10 +180,14 @@ public void setResetTokenAndSend(UserAccount userAccount) 
{
         final String email = userAccount.getEmail();
         final String username = userAccount.getUsername();
         final String subject = "Password Reset Request";
-        final String domainUrl = UserPasswordResetDomainURL.value();
+        String domainUrl = UserPasswordResetDomainURL.value();
+        if (StringUtils.isBlank(domainUrl)) {
+            domainUrl = ManagementServerAddresses.value().split(",")[0];
+        }
+        domainUrl = domainUrl.replaceAll("/+$", "");

Review Comment:
   The regex `/+$` removes trailing slashes. Consider also trimming 
leading/trailing whitespace with `.trim()` before this operation to handle 
potential whitespace from the configuration value or split operation: 
`domainUrl = domainUrl.trim().replaceAll(\"/+$\", \"\");`
   ```suggestion
           domainUrl = domainUrl.trim().replaceAll("/+$", "");
   ```



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