commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r620146 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/INIConfiguration.java test/org/apache/commons/configuration/TestINIConfiguration.java
Date Sat, 09 Feb 2008 16:33:46 GMT
Author: oheger
Date: Sat Feb  9 08:33:45 2008
New Revision: 620146

URL: http://svn.apache.org/viewvc?rev=620146&view=rev
Log:
CONFIGURATION-306: INIConfiguration now keeps whitespaces in property values that are quoted

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java?rev=620146&r1=620145&r2=620146&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java
Sat Feb  9 08:33:45 2008
@@ -400,7 +400,12 @@
             i++;
         }
 
-        return result.toString().trim();
+        String v = result.toString();
+        if(!quoted)
+        {
+            v = v.trim();
+        }
+        return v;
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java?rev=620146&r1=620145&r2=620146&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java
Sat Feb  9 08:33:45 2008
@@ -5,9 +5,9 @@
  * licenses this file to You under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -78,7 +78,7 @@
 		instance.addProperty("section3.multi", "foo");
 		instance.addProperty("section3.multi", "bar");
 		instance.save(writer);
-        
+
         assertEquals("Wrong content of ini file", INI_DATA, writer.toString());
 	}
 
@@ -209,5 +209,29 @@
         config2.load(new StringReader(writer.toString()));
 
         assertEquals("value", "1;2;3", config2.getString("section.key1"));
+    }
+
+    /**
+     * Tests whether whitespace is left unchanged for quoted values.
+     */
+    public void testQuotedValueWithWhitespace() throws Exception
+    {
+        final String content = "CmdPrompt = \" [test@cmd ~]$ \"";
+        INIConfiguration config = new INIConfiguration();
+        config.load(new StringReader(content));
+        assertEquals("Wrong propert value", " [test@cmd ~]$ ", config
+                .getString("CmdPrompt"));
+    }
+
+    /**
+     * Tests a quoted value with space and a comment.
+     */
+    public void testQuotedValueWithWhitespaceAndComment() throws Exception
+    {
+        final String content = "CmdPrompt = \" [test@cmd ~]$ \" ; a comment";
+        INIConfiguration config = new INIConfiguration();
+        config.load(new StringReader(content));
+        assertEquals("Wrong propert value", " [test@cmd ~]$ ", config
+                .getString("CmdPrompt"));
     }
 }



Mime
View raw message