geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r984135 - in /geronimo/xbean/trunk/xbean-reflect/src: main/java/org/apache/xbean/propertyeditor/ test/java/org/apache/xbean/recipe/
Date Tue, 10 Aug 2010 17:17:38 GMT
Author: gawor
Date: Tue Aug 10 17:17:37 2010
New Revision: 984135

URL: http://svn.apache.org/viewvc?rev=984135&view=rev
Log:
XBEAN-154: Do not trim input String when converting to String or Character types

Modified:
    geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/AbstractConverter.java
    geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/CharacterEditor.java
    geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/StringEditor.java
    geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/ObjectRecipeTest.java

Modified: geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/AbstractConverter.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/AbstractConverter.java?rev=984135&r1=984134&r2=984135&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/AbstractConverter.java
(original)
+++ geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/AbstractConverter.java
Tue Aug 10 17:17:37 2010
@@ -27,6 +27,7 @@ import java.beans.PropertyEditorSupport;
  */
 public abstract class AbstractConverter extends PropertyEditorSupport implements Converter
{
     private final Class type;
+    private final boolean trim;
 
     /**
      * Creates an abstract converter for the specified type.
@@ -34,9 +35,14 @@ public abstract class AbstractConverter 
      * @param type type of the property editor
      */
     protected AbstractConverter(Class type) {
+        this(type, true);
+    }
+    
+    protected AbstractConverter(Class type, boolean trim) {
         super();
         if (type == null) throw new NullPointerException("type is null");
         this.type = type;
+        this.trim = trim;
     }
 
     public final Class getType() {
@@ -50,7 +56,7 @@ public abstract class AbstractConverter 
     }
 
     public final void setAsText(String text) {
-        Object value = toObject(text.trim());
+        Object value = toObject((trim) ? text.trim() : text);
         super.setValue(value);
     }
 
@@ -77,7 +83,7 @@ public abstract class AbstractConverter 
             return null;
         }
 
-        Object value = toObjectImpl(text.trim());
+        Object value = toObjectImpl((trim) ? text.trim() : text);
         return value;
     }
 

Modified: geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/CharacterEditor.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/CharacterEditor.java?rev=984135&r1=984134&r2=984135&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/CharacterEditor.java
(original)
+++ geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/CharacterEditor.java
Tue Aug 10 17:17:37 2010
@@ -21,7 +21,7 @@ package org.apache.xbean.propertyeditor;
  */
 public class CharacterEditor extends AbstractConverter {
     public CharacterEditor() {
-        super(Character.class);
+        super(Character.class, false);
     }
 
     protected Object toObjectImpl(String text) {

Modified: geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/StringEditor.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/StringEditor.java?rev=984135&r1=984134&r2=984135&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/StringEditor.java
(original)
+++ geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/StringEditor.java
Tue Aug 10 17:17:37 2010
@@ -21,7 +21,7 @@ package org.apache.xbean.propertyeditor;
  */
 public class StringEditor extends AbstractConverter {
     public StringEditor() {
-        super(String.class);
+        super(String.class, false);
     }
 
     protected Object toObjectImpl(String text) {

Modified: geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/ObjectRecipeTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/ObjectRecipeTest.java?rev=984135&r1=984134&r2=984135&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/ObjectRecipeTest.java
(original)
+++ geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/ObjectRecipeTest.java
Tue Aug 10 17:17:37 2010
@@ -108,6 +108,24 @@ public class ObjectRecipeTest extends Te
         doTest(objectRecipe, PERSON_FACTORY_4_ARG);
     }
 
+    public void testWhitespaceInjection() throws Exception {
+        String name = " Foo Bar ";
+        char ch = ' ';
+        
+        ObjectRecipe objectRecipe = new ObjectRecipe(Value.class);
+        objectRecipe.setProperty("name", name);
+        objectRecipe.setProperty("type", " ");
+        Value c = (Value) objectRecipe.create();
+        
+        assertEquals(name, c.name);
+        assertEquals(ch, c.type);
+    }
+    
+    public static class Value {
+        public String name;
+        public char type;
+    }
+    
     private void doTest(ObjectRecipe objectRecipe, Person.ConstructionCalled expectedConstruction)
throws Exception {
         Person expected = new Person("Joe", 21, new URL("http://www.acme.org"), new Car("Mini",
"Cooper", 2008));
 



Mime
View raw message