bitflicker64 commented on code in PR #776:
URL: 
https://github.com/apache/hugegraph-toolchain/pull/776#discussion_r4183173098


##########
hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java:
##########
@@ -86,6 +99,43 @@ public Map<String, String> create(String name, String 
cloneGraphName, String con
         return result.readObject(Map.class);
     }
 
+    private static String legacyGraphConfig(String configText) {
+        Map<?, ?> config = JsonUtil.fromJson(configText, Map.class);
+        Properties properties = new Properties();
+        config.forEach((key, value) -> {
+            E.checkArgument(value instanceof String || value instanceof Number 
||
+                            value instanceof Boolean,
+                            "Legacy graph config option '%s' must be a scalar 
value", key);
+            properties.setProperty(key.toString(), value.toString());
+        });
+        StringWriter text = new StringWriter();
+        try {
+            properties.store(text, null);

Review Comment:
   Important: Non-ASCII config values are corrupted on any client JVM whose 
default charset is not UTF-8. `Properties.store(Writer, ...)` does not escape 
characters above `\u007E` (only the `OutputStream` overload does), so a value 
such as `李四` stays raw in `configText`. hugegraph-common's 
`AbstractRestClient.buildRequestBody` then sends it as 
`bodyContent.getBytes()`, which uses the platform charset, under `Content-Type: 
text/plain` with no charset parameter. Jersey on the 1.5 server decodes a 
charset-less `text/plain` String as UTF-8. On JDK 8 to 17 with a Windows-1252 
or GBK default, the server stores the wrong password or path, with no error. 
Reproduced on JDK 17: `"jdbc.password=李四é".getBytes()` under 
`-Dfile.encoding=windows-1252`, decoded as UTF-8, gives `jdbc.password=???`. 
`testLegacyConfigPreservesWhitespaceWithServerParser` does not catch this 
because it parses the Java String and never encodes it to bytes.
   
   The loop below already rewrites the stored text, so it can make the body 
pure ASCII. Commons Configuration decodes `\uXXXX`, and surrogate pairs come 
back intact because each half is escaped separately:
   
   ```java
   } else if (c == ' ') {
       encoded.append("\\u0020");
   } else if (c > 0x7E) {
       encoded.append(String.format("\\u%04x", (int) c));
   } else {
       encoded.append(c);
   }
   ```
   
   Please also add an assertion that the converted body is ASCII-only, for 
example `StandardCharsets.US_ASCII.newEncoder().canEncode(body)`, so the 
charset independence is tested.



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