bitflicker64 commented on code in PR #2944:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2944#discussion_r2751125571


##########
hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/config/HugeConfig.java:
##########
@@ -213,4 +221,53 @@ private static Configuration loadConfigFile(File 
configFile) {
                                       e, configFile);
         }
     }
+
+    private static Object normalizeUrlOptionIfNeeded(String key, Object value) 
{
+        if (value == null) {
+            return null;
+        }
+
+        String scheme = defaultSchemeFor(key);
+        if (scheme == null) {
+            return value;
+        }
+
+        // Normalize URL config values by adding default scheme if missing.
+        // Only applies to allowlisted URL options (see defaultSchemeFor()).
+        if (value instanceof String) {
+            return prefixSchemeIfMissing((String) value, scheme);
+        }
+
+        // If it ever hits here, it means config storage returned a non-string 
type;
+        // leave it unchanged (safer than forcing toString()).
+        return value;
+    }
+
+    private static String defaultSchemeFor(String key) {

Review Comment:
   fixed and added the following tests - 
   ```java    
   @Test
   public void testUrlNormalizationPreservesHostnameCase() {
       // Uppercase scheme + mixed-case hostname
       PropertiesConfiguration conf = new PropertiesConfiguration();
       conf.setProperty("restserver.url", "HTTP://MyServer:8080");
       HugeConfig config = new HugeConfig(conf);
       Assert.assertEquals("http://MyServer:8080";,
                           config.get(ServerOptions.REST_SERVER_URL));
   
       // HTTPS with mixed-case hostname
       conf = new PropertiesConfiguration();
       conf.setProperty("restserver.url", "HTTPS://MyHost:8080");
       config = new HugeConfig(conf);
       Assert.assertEquals("https://MyHost:8080";,
                           config.get(ServerOptions.REST_SERVER_URL));
   }
   
   @Test
   public void testUrlNormalizationPreservesPathCase() {
       PropertiesConfiguration conf = new PropertiesConfiguration();
       conf.setProperty("restserver.url", 
"http://127.0.0.1:8080/SomePath/CaseSensitive";);
       HugeConfig config = new HugeConfig(conf);
       Assert.assertEquals("http://127.0.0.1:8080/SomePath/CaseSensitive";,
                           config.get(ServerOptions.REST_SERVER_URL));
   }
   
   @Test
   public void testHttpsSchemeIsNotDowngraded() {
       PropertiesConfiguration conf = new PropertiesConfiguration();
       conf.setProperty("restserver.url", "https://127.0.0.1:8080";);
       HugeConfig config = new HugeConfig(conf);
       Assert.assertEquals("https://127.0.0.1:8080";,
                           config.get(ServerOptions.REST_SERVER_URL));
   }
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to