summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/spellchecker
diff options
context:
space:
mode:
authorgroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-27 21:26:51 +0000
committergroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-27 21:26:51 +0000
commitff7766242727b79e44144dcc171e00f414b2eb79 (patch)
treed23269242f352f2f6f83a32dd7983d08b3b6c2ae /chrome/renderer/spellchecker
parent5562d44a41387b1624c529d644057cfe92b9a950 (diff)
downloadchromium_src-ff7766242727b79e44144dcc171e00f414b2eb79.zip
chromium_src-ff7766242727b79e44144dcc171e00f414b2eb79.tar.gz
chromium_src-ff7766242727b79e44144dcc171e00f414b2eb79.tar.bz2
[Spellcheck] Don't initialize SpellcheckWordIterator with empty rulesets.
R=rlp@chromium.org BUG=none Review URL: https://chromiumcodereview.appspot.com/11413054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169761 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/spellchecker')
-rw-r--r--chrome/renderer/spellchecker/spellcheck_worditerator.cc5
-rw-r--r--chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc19
2 files changed, 24 insertions, 0 deletions
diff --git a/chrome/renderer/spellchecker/spellcheck_worditerator.cc b/chrome/renderer/spellchecker/spellcheck_worditerator.cc
index d6e6abe..466ac5d 100644
--- a/chrome/renderer/spellchecker/spellcheck_worditerator.cc
+++ b/chrome/renderer/spellchecker/spellcheck_worditerator.cc
@@ -312,6 +312,11 @@ bool SpellcheckWordIterator::Initialize(
UErrorCode open_status = U_ZERO_ERROR;
UParseError parse_status;
string16 rule(attribute->GetRuleSet(allow_contraction));
+
+ // If there is no rule set, the attributes were invalid.
+ if (rule.empty())
+ return false;
+
iterator_ = ubrk_openRules(rule.c_str(), rule.length(), NULL, 0,
&parse_status, &open_status);
if (U_FAILURE(open_status))
diff --git a/chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc b/chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc
index 1dc8614..f8d316a 100644
--- a/chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc
+++ b/chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc
@@ -228,3 +228,22 @@ TEST(SpellcheckWordIteratorTest, TreatNumbersAsWordCharacters) {
EXPECT_NE(input_word, actual_word);
}
}
+
+TEST(SpellcheckWordIteratorTest, Initialization) {
+ // Test initialization works when a default language is set.
+ {
+ SpellcheckCharAttribute attributes;
+ attributes.SetDefaultLanguage("en-US");
+
+ SpellcheckWordIterator iterator;
+ EXPECT_TRUE(iterator.Initialize(&attributes, true));
+ }
+
+ // Test initialization fails when no default language is set.
+ {
+ SpellcheckCharAttribute attributes;
+
+ SpellcheckWordIterator iterator;
+ EXPECT_FALSE(iterator.Initialize(&attributes, true));
+ }
+}