commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r955156 - in /commons/proper/cli/trunk/src: java/org/apache/commons/cli/Util.java test/org/apache/commons/cli/UtilTest.java
Date Wed, 16 Jun 2010 08:35:18 GMT
Author: ebourg
Date: Wed Jun 16 08:35:18 2010
New Revision: 955156

URL: http://svn.apache.org/viewvc?rev=955156&view=rev
Log:
Restricted quote stripping to values containing exactly 2 quotes, one at the beginning and
one at the end (CLI-185)

Modified:
    commons/proper/cli/trunk/src/java/org/apache/commons/cli/Util.java
    commons/proper/cli/trunk/src/test/org/apache/commons/cli/UtilTest.java

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli/Util.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli/Util.java?rev=955156&r1=955155&r2=955156&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli/Util.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli/Util.java Wed Jun 16 08:35:18
2010
@@ -62,14 +62,12 @@ class Util
      */
     static String stripLeadingAndTrailingQuotes(String str)
     {
-        if (str.startsWith("\""))
+        int length = str.length();
+        if (length > 1 && str.startsWith("\"") && str.endsWith("\"") &&
str.substring(1, length - 1).indexOf('"') == -1)
         {
-            str = str.substring(1, str.length());
-        }
-        if (str.endsWith("\""))
-        {
-            str = str.substring(0, str.length() - 1);
+            str = str.substring(1, length - 1);
         }
+        
         return str;
     }
 }

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/UtilTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/UtilTest.java?rev=955156&r1=955155&r2=955156&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/UtilTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/UtilTest.java Wed Jun 16 08:35:18
2010
@@ -35,5 +35,9 @@ public class UtilTest extends TestCase
     public void testStripLeadingAndTrailingQuotes()
     {
         assertEquals("foo", Util.stripLeadingAndTrailingQuotes("\"foo\""));
+        assertEquals("foo \"bar\"", Util.stripLeadingAndTrailingQuotes("foo \"bar\""));
+        assertEquals("\"foo\" bar", Util.stripLeadingAndTrailingQuotes("\"foo\" bar"));
+        assertEquals("\"foo\" and \"bar\"", Util.stripLeadingAndTrailingQuotes("\"foo\" and
\"bar\""));
+        assertEquals("\"", Util.stripLeadingAndTrailingQuotes("\""));
     }
 }



Mime
View raw message