diff options
author | Mattias Niklewski <mattias.niklewski@sonyericsson.com> | 2011-01-18 14:27:23 +0100 |
---|---|---|
committer | Johan Redestig <johan.redestig@sonyericsson.com> | 2011-04-04 14:52:35 +0200 |
commit | 114f98a75334813fe116da3d95567db8984d45b9 (patch) | |
tree | e3de45557e954b3aa4eb5cb5b084ee8c77f774b4 /core | |
parent | c6b22e2727bd3730edd5ad72831a9bb4670d00f3 (diff) | |
download | frameworks_base-114f98a75334813fe116da3d95567db8984d45b9.zip frameworks_base-114f98a75334813fe116da3d95567db8984d45b9.tar.gz frameworks_base-114f98a75334813fe116da3d95567db8984d45b9.tar.bz2 |
Always return a valid index from Rfc822Tokenizer.findTokenEnd()
If an invalid input string ends with a backslash inside a comment
or quoted string, the returned index would be past the end of the
string. In one case this would lead to a runtime exception being
thrown from MultiAutoCompleteTextView.performValidation.
Change-Id: If629372b429716c25cdc25764f088e95d4812d57
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/text/util/Rfc822Tokenizer.java | 4 | ||||
-rw-r--r-- | core/tests/coretests/src/android/text/TextUtilsTest.java | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/core/java/android/text/util/Rfc822Tokenizer.java b/core/java/android/text/util/Rfc822Tokenizer.java index 69cf93c..68334e4 100644 --- a/core/java/android/text/util/Rfc822Tokenizer.java +++ b/core/java/android/text/util/Rfc822Tokenizer.java @@ -256,7 +256,7 @@ public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer { if (c == '"') { i++; break; - } else if (c == '\\') { + } else if (c == '\\' && i + 1 < len) { i += 2; } else { i++; @@ -275,7 +275,7 @@ public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer { } else if (c == '(') { level++; i++; - } else if (c == '\\') { + } else if (c == '\\' && i + 1 < len) { i += 2; } else { i++; diff --git a/core/tests/coretests/src/android/text/TextUtilsTest.java b/core/tests/coretests/src/android/text/TextUtilsTest.java index e111662..79d57f1 100644 --- a/core/tests/coretests/src/android/text/TextUtilsTest.java +++ b/core/tests/coretests/src/android/text/TextUtilsTest.java @@ -255,6 +255,23 @@ public class TextUtilsTest extends TestCase { assertEquals("Foo Bar", tokens[0].getAddress()); } + @SmallTest + public void testRfc822FindToken() { + Rfc822Tokenizer tokenizer = new Rfc822Tokenizer(); + // 0 1 2 3 4 + // 0 1234 56789012345678901234 5678 90123456789012345 + String address = "\"Foo\" <foo@google.com>, \"Bar\" <bar@google.com>"; + assertEquals(0, tokenizer.findTokenStart(address, 21)); + assertEquals(22, tokenizer.findTokenEnd(address, 21)); + assertEquals(24, tokenizer.findTokenStart(address, 25)); + assertEquals(46, tokenizer.findTokenEnd(address, 25)); + } + + @SmallTest + public void testRfc822FindTokenWithError() { + assertEquals(9, new Rfc822Tokenizer().findTokenEnd("\"Foo Bar\\", 0)); + } + @LargeTest public void testEllipsize() { CharSequence s1 = "The quick brown fox jumps over \u00FEhe lazy dog."; |