FELIX-4289 : Spaces within values are removed for default values

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1535353 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/metatype/src/main/java/org/apache/felix/metatype/AD.java b/metatype/src/main/java/org/apache/felix/metatype/AD.java
index 6d08ece..d208450 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/AD.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/AD.java
@@ -354,10 +354,20 @@
 
         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 @@
                     // 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;
         }
diff --git a/metatype/src/test/java/org/apache/felix/metatype/ADTest.java b/metatype/src/test/java/org/apache/felix/metatype/ADTest.java
index 6f475c8..82c9c6d 100644
--- a/metatype/src/test/java/org/apache/felix/metatype/ADTest.java
+++ b/metatype/src/test/java/org/apache/felix/metatype/ADTest.java
@@ -120,6 +120,18 @@
         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";