[Checkins] SVN: zope.index/trunk/ Avoid raising an exception when indexing None.
Tres Seaver
tseaver at palladion.com
Thu Jul 8 12:51:02 EDT 2010
Log message for revision 114343:
Avoid raising an exception when indexing None.
Fixes LP #598776.
Changed:
U zope.index/trunk/CHANGES.txt
U zope.index/trunk/src/zope/index/text/lexicon.py
U zope.index/trunk/src/zope/index/text/tests/test_lexicon.py
-=-
Modified: zope.index/trunk/CHANGES.txt
===================================================================
--- zope.index/trunk/CHANGES.txt 2010-07-08 16:29:19 UTC (rev 114342)
+++ zope.index/trunk/CHANGES.txt 2010-07-08 16:51:02 UTC (rev 114343)
@@ -4,7 +4,7 @@
Unreleased
----------
-- ... -\|/- ...
+- Avoid raising an exception when indexing None. (LP #598776)
3.6.0 (2009-08-03)
------------------
Modified: zope.index/trunk/src/zope/index/text/lexicon.py
===================================================================
--- zope.index/trunk/src/zope/index/text/lexicon.py 2010-07-08 16:29:19 UTC (rev 114342)
+++ zope.index/trunk/src/zope/index/text/lexicon.py 2010-07-08 16:51:02 UTC (rev 114343)
@@ -59,6 +59,8 @@
return self._wids.items()
def sourceToWordIds(self, text):
+ if text is None:
+ text = ''
last = _text2list(text)
for element in self._pipeline:
last = element.process(last)
Modified: zope.index/trunk/src/zope/index/text/tests/test_lexicon.py
===================================================================
--- zope.index/trunk/src/zope/index/text/tests/test_lexicon.py 2010-07-08 16:29:19 UTC (rev 114342)
+++ zope.index/trunk/src/zope/index/text/tests/test_lexicon.py 2010-07-08 16:51:02 UTC (rev 114343)
@@ -53,6 +53,17 @@
# No write-on-read!
self.failIf(isinstance(lexicon.wordCount, Length))
+ def test_sourceToWordIds_empty_string(self):
+ lexicon = self._makeOne()
+ wids = lexicon.sourceToWordIds('')
+ self.assertEqual(wids, [])
+
+ def test_sourceToWordIds_none(self):
+ # See LP #598776
+ lexicon = self._makeOne()
+ wids = lexicon.sourceToWordIds(None)
+ self.assertEqual(wids, [])
+
def test_sourceToWordIds(self):
lexicon = self._makeOne()
wids = lexicon.sourceToWordIds('cats and dogs')
More information about the checkins
mailing list