velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1834387 - /velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
Date Tue, 26 Jun 2018 00:47:22 GMT
Author: cbrisson
Date: Tue Jun 26 00:47:22 2018
New Revision: 1834387

URL: http://svn.apache.org/viewvc?rev=1834387&view=rev
Log:
[tools] fix VELTOOLS-168 - LinkTool internal query should only contain scalars or Lists, never
arrays

Modified:
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java?rev=1834387&r1=1834386&r2=1834387&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
Tue Jun 26 00:47:22 2018
@@ -20,6 +20,7 @@ package org.apache.velocity.tools.generi
  */
 
 import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Array;
 import java.net.URI;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
@@ -27,6 +28,7 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.ToolContext;
@@ -439,7 +441,35 @@ public class LinkTool extends SafeConfig
         }
         else if (obj instanceof Map)
         {
-            this.query = new LinkedHashMap((Map)obj);
+            this.query = new LinkedHashMap();
+            for (Map.Entry keyValues : (Set<Map.Entry>)((Map)obj).entrySet())
+            {
+                String key = String.valueOf(keyValues.getKey());
+                Object values = keyValues.getValue();
+                if (values.getClass().isArray())
+                {
+                    int size = Array.getLength(values);
+                    switch (size)
+                    {
+                        case 0:
+                            break;
+                        case 1:
+                            this.query.put(key, Array.get(values, 0));
+                            break;
+                        default:
+                            List lst = new ArrayList();
+                            for (int i = 0; i < Array.getLength(values); ++i)
+                            {
+                                lst.add(Array.get(values, i));
+                            }
+                            this.query.put(key, lst);
+                    }
+                }
+                else
+                {
+                    this.query.put(key, values);
+                }
+            }
         }
         else
         {



Mime
View raw message