diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
index 4e290024c8eb435811c6e9436d14fb30a59b6e4b..adb5f4759618342c03bf6c1cdd184a760c3b81ac 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
@@ -325,7 +325,7 @@ public class KeySpecParser {
             return null;
         }
         if (Utils.codePointCount(text) == 1) {
-            return new String[] { text };
+            return text.codePointAt(0) == COMMA ? null : new String[] { text };
         }
 
         ArrayList<String> list = null;
@@ -333,10 +333,13 @@ public class KeySpecParser {
         for (int pos = 0; pos < size; pos++) {
             final char c = text.charAt(pos);
             if (c == COMMA) {
-                if (list == null) {
-                    list = new ArrayList<String>();
+                // Skip empty entry.
+                if (pos - start > 0) {
+                    if (list == null) {
+                        list = new ArrayList<String>();
+                    }
+                    list.add(text.substring(start, pos));
                 }
-                list.add(text.substring(start, pos));
                 // Skip comma
                 start = pos + 1;
             } else if (c == ESCAPE_CHAR) {
@@ -344,10 +347,13 @@ public class KeySpecParser {
                 pos++;
             }
         }
+        final String remain = (size - start > 0) ? text.substring(start) : null;
         if (list == null) {
-            return new String[] { text.substring(start) };
+            return remain != null ? new String[] { remain } : null;
         } else {
-            list.add(text.substring(start));
+            if (remain != null) {
+                list.add(remain);
+            }
             return list.toArray(new String[list.size()]);
         }
     }
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java
index 721c801e1de90833afeaf0e68d90f8e0451fad9a..a0ce86d1c07d76d49bcd1bf5da49666bb991baca 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java
@@ -42,7 +42,8 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
         final String actual[] = KeySpecParser.parseCsvString(value, mTestResources,
                 R.string.empty_string);
         if (expected.length == 0) {
-            assertNull(message, actual);
+            assertNull(message + ": expected=null actual=" + Arrays.toString(actual),
+                    actual);
             return;
         }
         assertEquals(message + ": expected=" + Arrays.toString(expected)
@@ -74,6 +75,11 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
 
     public void testParseCsvTextZero() {
         assertTextArray("Empty string", "");
+        assertTextArray("Empty entry", ",");
+        assertTextArray("Empty entry at beginning", ",a", "a");
+        assertTextArray("Empty entry at end", "a,", "a");
+        assertTextArray("Empty entry at middle", "a,,b", "a", "b");
+        assertTextArray("Empty entries with escape", ",a,b\\,c,,d,", "a", "b\\,c", "d");
     }
 
     public void testParseCsvTextSingle() {
@@ -82,7 +88,7 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
         assertTextArray("Single escape", "\\", "\\");
         assertTextArray("Space", " ", " ");
         assertTextArray("Single label", "abc", "abc");
-        assertTextArray("Single srrogate pairs label", SURROGATE2, SURROGATE2);
+        assertTextArray("Single surrogate pairs label", SURROGATE2, SURROGATE2);
         assertTextArray("Spaces", "   ", "   ");
         assertTextArray("Spaces in label", "a b c", "a b c");
         assertTextArray("Spaces at beginning of label", " abc", " abc");