liubao68 commented on a change in pull request #2688:
URL:
https://github.com/apache/servicecomb-java-chassis/pull/2688#discussion_r801241982
##########
File path:
foundations/foundation-config/src/main/java/org/apache/servicecomb/config/YAMLUtil.java
##########
@@ -55,15 +55,34 @@ private YAMLUtil() {
public static Map<String, Object> yaml2Properties(InputStream input) {
Map<String, Object> configurations = new LinkedHashMap<>();
SAFE_PARSER.loadAll(input).forEach(data -> {
- if (data instanceof Map) {
+ if (data instanceof Map && isValidMap((Map<Object, Object>) data)) {
configurations.putAll(retrieveItems("", (Map<String, Object>) data));
} else {
- LOGGER.warn("input cannot be convert to map");
+ throw new IllegalArgumentException("input cannot be convert to map");
}
});
return configurations;
}
+ @SuppressWarnings("unchecked")
+ private static boolean isValidMap(Map<Object, Object> data) {
+ boolean flag = false;
+ for (Map.Entry<Object, Object> entry : data.entrySet()) {
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+ if (key instanceof String) {
+ if (value instanceof Map) {
+ return isValidMap((Map<Object, Object>) value);
+ } else {
+ flag = true;
+ }
+ } else {
+ flag = false;
+ }
+ }
+ return flag;
+ }
+
Review comment:
```
private static boolean isValidMap(Map<Object, Object> data) {
for (Map.Entry<Object, Object> entry : data.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
if (key instanceof String) {
if (value instanceof Map) {
return isValidMap((Map<Object, Object>) value);
}
continue;
}
return false;
}
return true;
}
```
--
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]