diff options
-rw-r--r-- | core/java/android/text/util/Rfc822Tokenizer.java | 8 | ||||
-rw-r--r-- | tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java | 20 |
2 files changed, 26 insertions, 2 deletions
diff --git a/core/java/android/text/util/Rfc822Tokenizer.java b/core/java/android/text/util/Rfc822Tokenizer.java index cb39f7d..3a67e20 100644 --- a/core/java/android/text/util/Rfc822Tokenizer.java +++ b/core/java/android/text/util/Rfc822Tokenizer.java @@ -86,7 +86,9 @@ public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer { i++; break; } else if (c == '\\') { - name.append(text.charAt(i + 1)); + if (i + 1 < cursor) { + name.append(text.charAt(i + 1)); + } i += 2; } else { name.append(c); @@ -112,7 +114,9 @@ public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer { level++; i++; } else if (c == '\\') { - comment.append(text.charAt(i + 1)); + if (i + 1 < cursor) { + comment.append(text.charAt(i + 1)); + } i += 2; } else { comment.append(c); diff --git a/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java b/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java index 7720041..bb32da0 100644 --- a/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java +++ b/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java @@ -29,6 +29,8 @@ import android.text.SpannedString; import android.text.TextPaint; import android.text.TextUtils; import android.text.style.StyleSpan; +import android.text.util.Rfc822Token; +import android.text.util.Rfc822Tokenizer; import android.text.util.Rfc822Validator; import android.test.MoreAsserts; @@ -269,6 +271,24 @@ public class TextUtilsTest extends TestCase { } } + @SmallTest + public void testRfc822TokenizerFullAddress() { + Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("Foo Bar (something) <foo@google.com>"); + assertNotNull(tokens); + assertEquals(1, tokens.length); + assertEquals("foo@google.com", tokens[0].getAddress()); + assertEquals("Foo Bar", tokens[0].getName()); + assertEquals("something",tokens[0].getComment()); + } + + @SmallTest + public void testRfc822TokenizeItemWithError() { + Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("\"Foo Bar\\"); + assertNotNull(tokens); + assertEquals(1, tokens.length); + assertEquals("Foo Bar", tokens[0].getAddress()); + } + @LargeTest public void testEllipsize() { CharSequence s1 = "The quick brown fox jumps over \u00FEhe lazy dog."; |