bitflicker64 commented on code in PR #2944:
URL:
https://github.com/apache/incubator-hugegraph/pull/2944#discussion_r2732101647
##########
hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/config/HugeConfig.java:
##########
@@ -213,4 +217,55 @@ 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;
+ }
+
+ // URL options are defined as ConfigOption<String> and normalized here.
+ 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) {
+ switch (key) {
+ case "restserver.url":
+ case "gremlinserver.url":
+ case "server.urls_to_pd":
+ return "http://";
+ case "server.k8s_url":
+ return "https://";
+ default:
+ return null;
+ }
+ }
+
+ private static String prefixSchemeIfMissing(String raw, String scheme) {
+ if (raw == null) {
+ return null;
+ }
+ String s = raw.trim();
+ if (s.isEmpty()) {
+ return s;
+ }
+
+ // Keep original string if scheme already exists
+ String lower = s.toLowerCase();
+ if (lower.startsWith("http://") || lower.startsWith("https://")) {
+ return s;
+ }
Review Comment:
The prefixSchemeIfMissing() method currently just normalizes URLs and
doesn’t try to validate things like userinfo (user@host). That seems reasonable
since handling credentials in URLs is discouraged and @ can also appear in
valid paths. Adding special checks here would blur the line between
normalization and validation.It’s probably better to handle stricter validation
at the client/usage layer if needed.I’m happy to add a separate check or open
an additional PR if you think stricter handling belongs here. Please let me
know your preference.
--
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]