[
https://issues.apache.org/struts/browse/WW-3136?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46235#action_46235
]
Musachy Barroso commented on WW-3136:
-------------------------------------
forgot to say, the json plugin is not even part of struts
> jsonplugin JSONResult.setIncludeProperties(String commaDelim) doesnt process
> includeProperties properly
> -------------------------------------------------------------------------------------------------------
>
> Key: WW-3136
> URL: https://issues.apache.org/struts/browse/WW-3136
> Project: Struts 2
> Issue Type: Bug
> Components: Other
> Affects Versions: 2.1.6
> Environment: JDK 6
> Struts2-1.6
> latest json-plugin
> Reporter: Martin Gainty
>
> //rather lengthy testcase for includeProperties
> com.googlecode.jsonplugin.JSONResultTest
> public void testIncludePropertiesWithList() throws Exception {
> JSONResult result = new JSONResult();
> /*public class JSONResult implements Result {
> private static final long serialVersionUID = 8624350183189931165L;
> private String defaultEncoding = "ISO-8859-1";
> private List<Pattern> includeProperties; //you want to initialise this!
> */
> result.setIncludeProperties("^list\\[\\d+\\]\\.booleanField");
> /*** @param includedProperties the includeProperties to set
> */
> public void setIncludeProperties(String commaDelim) {
> List<String> includePatterns = JSONUtil.asList(commaDelim);
> //splits all Strings using , as delimiter
> /* public static List<String> asList(String commaDelim) {
> if ((commaDelim == null) || (commaDelim.trim().length() == 0))
> return null;
> List<String> list = new ArrayList<String>();
> String[] split = commaDelim.split(",");
> for (int i = 0; i < split.length; i++) {
> String trimmed = split[i].trim();
> if (trimmed.length() > 0) {
> list.add(trimmed);
> }
> }
> return list;
> }
> */
> if (includePatterns != null) //TRUE
> {
> this.includeProperties = new
> ArrayList<Pattern>(includePatterns.size());
> //includeProperties now includes ArrayList<Pattern>
> HashMap existingPatterns = new HashMap();
> for (String pattern : includePatterns) {
> // Compile a pattern for each *unique* "level" of the object
> // hierarchy specified in the regex.
> //split according to \ delimiter found
> String[] patternPieces = pattern.split("\\\\\\.");
> String patternExpr = "";
> //the individual patternPieces will be referred to as patternPiece
> for (String patternPiece : patternPieces)
> {
> //patternExpr is null on first go-around (bypass this logic on first
> go-around)
> if (patternExpr.length() > 0)
> {
> patternExpr += "\\.";
> }
> patternExpr += patternPiece; //patternExpr=patternPiece
> // Check for duplicate patterns so that there is no overlap.
> //first go around will always execute logic as !existingPatterns returns true
> if (!existingPatterns.containsKey(patternExpr))
> {
> //doesnt make sense..if existingPatterns already contains patternExpr why add
> it again?
> //would'nt you want to leave existingPatterns HashMap alone?
> existingPatterns.put(patternExpr, patternExpr);
> //Add a pattern that does not have the indexed property matching (ie.
> list\[\d+\] //becomes list).
> //look for the end in the piece we have
> if (patternPiece.endsWith("\\]"))
> {
> //doesnt make sense..you're testing patternPiece.lastIndexOf("\\["))));
> //then why compile patternExpr?
> //why not take the relevant patternPiece and assign it to patternExpr
> //then let the statement later in the code
> this.includeProperties.add(Pattern.compile(patternExpr)); handle this?
>
> this.includeProperties.add(Pattern.compile(patternExpr.substring(0,
> patternPiece.lastIndexOf("\\["))));
> //enable the log so we can see this message
> if (log.isDebugEnabled())
> log.debug("Adding include property
> expression: " + patternExpr.substring(0, patternPiece.lastIndexOf("\\[")));
> }
> //this unconditionally adds the (compiled version of) patternExpr to
> includeProperties
>
> this.includeProperties.add(Pattern.compile(patternExpr));
> if (log.isDebugEnabled())
> log.debug("Adding include property expression: "
> + patternExpr);
> }
> }
> }
> }
> }
> */
> from what i can see there is a bug with JSONResult
> public void setIncludeProperties(String commaDelim) method
> ?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.