From 5bf55a86d0dd55ade42833fdb7cf654b2aeddb4e Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 6 Dec 2013 16:41:34 +0900 Subject: [PATCH] Return null if "!text/" reference is an empty text Change-Id: I01826f3e09527348fb4cba3302a9394ff34f424a --- .../inputmethod/keyboard/internal/KeySpecParser.java | 11 +++++++---- .../keyboard/internal/KeySpecParserSplitTests.java | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index cb4663777..accfaedcb 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -78,10 +78,10 @@ public final class KeySpecParser { * or has no key specifications. */ public static String[] splitKeySpecs(final String text) { - final int size = text.length(); - if (size == 0) { + if (TextUtils.isEmpty(text)) { return null; } + final int size = text.length(); // Optimization for one-letter key specification. if (size == 1) { return text.charAt(0) == COMMA ? null : new String[] { text }; @@ -380,6 +380,9 @@ public final class KeySpecParser { public static String resolveTextReference(final String rawText, final KeyboardTextsSet textsSet) { + if (TextUtils.isEmpty(rawText)) { + return null; + } int level = 0; String text = rawText; StringBuilder sb; @@ -392,7 +395,7 @@ public final class KeySpecParser { final int prefixLen = PREFIX_TEXT.length(); final int size = text.length(); if (size < prefixLen) { - return text; + return TextUtils.isEmpty(text) ? null : text; } sb = null; @@ -421,7 +424,7 @@ public final class KeySpecParser { text = sb.toString(); } } while (sb != null); - return text; + return TextUtils.isEmpty(text) ? null : text; } private static int searchTextNameEnd(final String text, final int start) { diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserSplitTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserSplitTests.java index 2eb448c82..cbe2d5960 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserSplitTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserSplitTests.java @@ -116,6 +116,16 @@ public class KeySpecParserSplitTests extends InstrumentationTestCase { private static final String SURROGATE1 = PAIR1 + PAIR2; private static final String SURROGATE2 = PAIR1 + PAIR2 + PAIR3; + public void testResolveNullText() { + assertNull("resolve null", KeySpecParser.resolveTextReference( + null, mTextsSet)); + } + + public void testResolveEmptyText() { + assertNull("resolve empty text", KeySpecParser.resolveTextReference( + "!text/empty_string", mTextsSet)); + } + public void testSplitZero() { assertTextArray("Empty string", ""); assertTextArray("Empty entry", ",");