We have a problem in Jetspeed when saving ExtendedProperties. One of the 
properties is a URL that may contain a comma. This gives problems, as it 
does not get encoded on "save", and thus gives a ClassCastException on 
"load".

I am currently testing this patch. If you think it is OK, please use it.
(I hope java can optimize tail recursion, and I hope also I did not made 
any mistake with int indexes... :)

Not fully tested. Compiles, I'm testing functional behaviour.

Index: src/java/org/apache/turbine/util/ExtendedProperties.java
===================================================================
RCS file: 
/products/cvs/turbine/turbine/src/java/org/apache/turbine/util/ExtendedProperties.java,v
retrieving revision 1.1
diff -u -r1.1 ExtendedProperties.java
--- src/java/org/apache/turbine/util/ExtendedProperties.java 
2001/01/05 00:04:29     1.1
+++ src/java/org/apache/turbine/util/ExtendedProperties.java 
2001/02/15 21:03:04
@@ -136,6 +136,7 @@
   * @see org.apache.turbine.util.Configurations
   * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Santiago Gala</a>
   * @version $Id: ExtendedProperties.java,v 1.1 2001/01/05 00:04:29 dlr 
Exp $
   */
  public class ExtendedProperties
@@ -442,7 +443,7 @@
                          StringBuffer currentOutput = new StringBuffer();
                          currentOutput.append(key);
                          currentOutput.append("=");
-                        currentOutput.append((String) value);
+                        writeEscaped(currentOutput, (String) value);
                          theWrtr.println(currentOutput.toString());
                      }
                      else if(value instanceof Vector)
@@ -456,7 +457,7 @@
                              StringBuffer currentOutput = new 
StringBuffer();
                              currentOutput.append(key);
                              currentOutput.append("=");
-                            currentOutput.append(currentElement);
+                            writeEscaped(currentOutput, currentElement);
                              theWrtr.println(currentOutput.toString());
                          }
                      }
@@ -465,5 +466,22 @@
                  theWrtr.flush();
              }
          }
+    }
+
+    /**
+     * Escape values when saving.
+     * Appends a String to a StringBuffer, escaping commas.
+     * @param sink a StringBuffer to write output
+     * @param element a value to be written
+     */
+    protected void writeEscaped( StringBuffer sink, String element ) {
+        int upTo = element.indexOf(",");
+        if( upTo == -1 ) {
+            sink.append( element );
+            return;
+        }
+        sink.append( element.substring( upTo ) );
+        writeEscaped( sink, element.substring( upTo+1, element.length() 
) );
+        return;
      }
  }



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to