felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1535353 - in /felix/trunk/metatype/src: main/java/org/apache/felix/metatype/AD.java test/java/org/apache/felix/metatype/ADTest.java
Date Thu, 24 Oct 2013 12:34:05 GMT
Author: cziegeler
Date: Thu Oct 24 12:34:04 2013
New Revision: 1535353

URL: http://svn.apache.org/r1535353
Log:
FELIX-4289 : Spaces within values are removed for default values

Modified:
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/AD.java
    felix/trunk/metatype/src/test/java/org/apache/felix/metatype/ADTest.java

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/AD.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/AD.java?rev=1535353&r1=1535352&r2=1535353&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/AD.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/AD.java Thu Oct 24 12:34:04
2013
@@ -354,10 +354,20 @@ public class AD extends OptionalAttribut
 
         int length = listString.length();
         boolean escaped = false;
-
+        int spaceCount = 0;
+        boolean start = true;
         for (int i = 0; i < length; i++)
         {
             char ch = listString.charAt(i);
+            final boolean isWhitespace = Character.isWhitespace(ch);
+            if ( start )
+            {
+                if ( isWhitespace )
+                {
+                    continue;
+                }
+                start = false;
+            }
             if (ch == '\\')
             {
                 if (!escaped)
@@ -373,23 +383,33 @@ public class AD extends OptionalAttribut
                     // unescaped comma, this is a string delimiter...
                     strings.add(sb.toString());
                     sb.setLength(0);
+                    start = true;
+                    spaceCount = 0;
                     continue;
                 }
-            }
-            else if (ch == ' ')
+            } else if ( ch == ' ')
             {
-                // we should ignore spaces normally, unless they are escaped...
-                if (!escaped)
+                // space is only ignored at beginning and end but not if escaped
+                if (!escaped )
                 {
+                    spaceCount++;
                     continue;
                 }
             }
-            else if (Character.isWhitespace(ch))
+            else if (isWhitespace )
             {
                 // Other whitespaces are ignored...
                 continue;
             }
 
+            if ( spaceCount > 0)
+            {
+                for(int m = 0; m<spaceCount; m++)
+                {
+                    sb.append(" ");
+                }
+                spaceCount = 0;
+            }
             sb.append(ch);
             escaped = false;
         }

Modified: felix/trunk/metatype/src/test/java/org/apache/felix/metatype/ADTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/test/java/org/apache/felix/metatype/ADTest.java?rev=1535353&r1=1535352&r2=1535353&view=diff
==============================================================================
--- felix/trunk/metatype/src/test/java/org/apache/felix/metatype/ADTest.java (original)
+++ felix/trunk/metatype/src/test/java/org/apache/felix/metatype/ADTest.java Thu Oct 24 12:34:04
2013
@@ -120,6 +120,18 @@ public class ADTest extends TestCase
         assertEquals(value1, list[1]);
     }
 
+    public void testSpaces()
+    {
+        String value = "Hello World";
+        String listString = BLANK + value + BLANK + "," + BLANK + value + BLANK + "," +value;
+        String[] list = AD.splitList(listString);
+        assertNotNull(list);
+        assertEquals(3, list.length);
+        assertEquals(value, list[0]);
+        assertEquals(value, list[1]);
+        assertEquals(value, list[2]);
+    }
+
     public void testStandardSample()
     {
         String value0 = "a,b";



Mime
View raw message