andruhon commented on a change in pull request #378: WICKET-6688 add RFC support (to avoid unsafe eval) URL: https://github.com/apache/wicket/pull/378#discussion_r304820758
########## File path: wicket-core/src/main/java/org/apache/wicket/ajax/RemoteFunctionCallUtils.java ########## @@ -0,0 +1,43 @@ +package org.apache.wicket.ajax; + +import com.github.openjson.JSONObject; +import org.apache.wicket.ajax.json.JSONFunction; +import org.apache.wicket.ajax.json.JsonUtils; +import org.apache.wicket.util.string.Strings; +import org.junit.platform.commons.util.StringUtils; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class RemoteFunctionCallUtils +{ + public static String createFunctionJsonString(CharSequence functionName, Object ... args) + { + return "{\"func\":" + wrapAndEscape(functionName) + "," + + "\"args\":[" + + Arrays.stream(args).map(RemoteFunctionCallUtils::wrapAndEscape).collect(Collectors.joining(",")) + + "]}"; + } + + /** + * Currently works only with primitives + * @param arg + * @return + */ + public static String wrapAndEscape(Object arg) + { + if (arg instanceof Number || arg instanceof Boolean) + { + return String.valueOf(arg); + } else if (arg instanceof JSONObject) { + return arg.toString(); + } else Review comment: What's up with formatting? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services