svn commit: r1536170 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1536170 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java

adrianc
Author: adrianc
Date: Sun Oct 27 18:06:15 2013
New Revision: 1536170

URL: http://svn.apache.org/r1536170
Log:
Small fix for StringUtil.toMap method - avoid array index exceptions when a Map element is missing a value.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=1536170&r1=1536169&r2=1536170&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java Sun Oct 27 18:06:15 2013
@@ -377,7 +377,9 @@ public class StringUtil {
     }
     
     /**
-     * Reads a String version of a Map (should contain only strings) and creates a new Map
+     * Reads a String version of a Map (should contain only strings) and creates a new Map.
+     * Partial Map elements are skipped: <code>{foo=fooValue, bar=}</code> will contain only
+     * the foo element.
      *
      * @param s String value of a Map ({n1=v1, n2=v2})
      * @return new Map
@@ -389,7 +391,9 @@ public class StringUtil {
             String[] entries = s.split("\\,\\s");
             for (String entry: entries) {
                 String[] nv = entry.split("\\=");
-                newMap.put(nv[0], nv[1]);
+                if (nv.length == 2) {
+                    newMap.put(nv[0], nv[1]);
+                }
             }
         } else {
             throw new IllegalArgumentException("String is not from Map.toString()");