[Checkins] SVN: Products.ZCatalog/branches/2.13/ Strip white space from name when adding a column or index.
Maurits van Rees
cvs-admin at zope.org
Thu Sep 27 21:20:24 UTC 2012
Log message for revision 127899:
Strip white space from name when adding a column or index.
I have seen this in a live site and it is tricky to figure out what is wrong.
Solution if it is too late: delete the column or index and recreate without the space.
For the column, rebuild the catalog. For the index, index that particular index.
This is merged from trunk, r127898.
Changed:
U Products.ZCatalog/branches/2.13/CHANGES.txt
U Products.ZCatalog/branches/2.13/src/Products/ZCatalog/Catalog.py
U Products.ZCatalog/branches/2.13/src/Products/ZCatalog/tests/test_catalog.py
-=-
Modified: Products.ZCatalog/branches/2.13/CHANGES.txt
===================================================================
--- Products.ZCatalog/branches/2.13/CHANGES.txt 2012-09-27 21:11:27 UTC (rev 127898)
+++ Products.ZCatalog/branches/2.13/CHANGES.txt 2012-09-27 21:20:21 UTC (rev 127899)
@@ -4,6 +4,7 @@
2.13.24 (unreleased)
--------------------
+- Strip white space from name when adding a column or index.
2.13.23 (2012-04-26)
--------------------
Modified: Products.ZCatalog/branches/2.13/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/branches/2.13/src/Products/ZCatalog/Catalog.py 2012-09-27 21:11:27 UTC (rev 127898)
+++ Products.ZCatalog/branches/2.13/src/Products/ZCatalog/Catalog.py 2012-09-27 21:20:21 UTC (rev 127899)
@@ -158,6 +158,13 @@
schema = self.schema
names = list(self.names)
+ if name != name.strip():
+ # Someone could have mistakenly added a space at the end
+ # of the input field.
+ LOG.warn("stripped space from new column %r -> %r", name,
+ name.strip())
+ name = name.strip()
+
if name in schema:
raise CatalogError('The column %s already exists' % name)
@@ -239,6 +246,13 @@
if not name:
raise CatalogError('Name of index is empty')
+ if name != name.strip():
+ # Someone could have mistakenly added a space at the end
+ # of the input field.
+ LOG.warn("stripped space from new index %r -> %r", name,
+ name.strip())
+ name = name.strip()
+
indexes = self.indexes
if isinstance(index_type, str):
Modified: Products.ZCatalog/branches/2.13/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Products.ZCatalog/branches/2.13/src/Products/ZCatalog/tests/test_catalog.py 2012-09-27 21:11:27 UTC (rev 127898)
+++ Products.ZCatalog/branches/2.13/src/Products/ZCatalog/tests/test_catalog.py 2012-09-27 21:20:21 UTC (rev 127899)
@@ -94,6 +94,13 @@
from Products.ZCatalog.Catalog import CatalogError
self.assertRaises(CatalogError, self._catalog.addColumn, '_id')
+ def testAddWithSpace(self):
+ self._catalog.addColumn(' space ')
+ self.assertEqual(' space ' not in self._catalog.schema, True,
+ 'space not stripped in add column')
+ self.assertEqual('space' in self._catalog.schema, True,
+ 'stripping space in add column failed')
+
def testDel(self):
self._catalog.addColumn('id')
self._catalog.delColumn('id')
@@ -125,6 +132,17 @@
self.assert_(isinstance(i, type(KeywordIndex('id'))),
'add kw index failed')
+ def testAddWithSpace(self):
+ idx = KeywordIndex(' space ')
+ self._catalog.addIndex(' space ', idx)
+ self.assertEqual(' space ' not in self._catalog.indexes, True,
+ 'space not stripped in add index')
+ self.assertEqual('space' in self._catalog.indexes, True,
+ 'stripping space in add index failed')
+ i = self._catalog.indexes['space']
+ # Note: i.id still has spaces in it.
+ self.assert_(isinstance(i, KeywordIndex))
+
def testDelFieldIndex(self):
idx = FieldIndex('id')
self._catalog.addIndex('id', idx)
More information about the checkins
mailing list