[Checkins] SVN: Products.ZCatalog/trunk/ Strip white space from name when adding a column or index.
Maurits van Rees
cvs-admin at zope.org
Thu Sep 27 21:11:32 UTC 2012
Log message for revision 127898:
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.
Changed:
U Products.ZCatalog/trunk/CHANGES.txt
U Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
U Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt 2012-09-27 11:59:21 UTC (rev 127897)
+++ Products.ZCatalog/trunk/CHANGES.txt 2012-09-27 21:11:27 UTC (rev 127898)
@@ -4,6 +4,8 @@
3.0b2 (unreleased)
------------------
+- Strip white space from name when adding a column or index.
+
- Forward compatibility for Zope 4 removal of RequestContainer.
- Optimize brain instantiation, by creating underlying record items in a
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-09-27 11:59:21 UTC (rev 127897)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-09-27 21:11:27 UTC (rev 127898)
@@ -165,6 +165,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)
@@ -247,6 +254,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/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py 2012-09-27 11:59:21 UTC (rev 127897)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py 2012-09-27 21:11:27 UTC (rev 127898)
@@ -77,6 +77,14 @@
catalog = self._make_one()
self.assertRaises(CatalogError, catalog.addColumn, '_id')
+ def test_add_with_space(self):
+ catalog = self._make_one()
+ catalog.addColumn(' space ')
+ self.assertEqual(' space ' not in catalog.schema, True,
+ 'space not stripped in add column')
+ self.assertEqual('space' in catalog.schema, True,
+ 'stripping space in add column failed')
+
def test_add_brains(self):
catalog = self._make_one()
catalog.addColumn('col1')
@@ -135,6 +143,18 @@
i = catalog.indexes['id']
self.assert_(isinstance(i, KeywordIndex))
+ def test_add_with_space(self):
+ catalog = self._make_one()
+ idx = KeywordIndex(' space ')
+ catalog.addIndex(' space ', idx)
+ self.assertEqual(' space ' not in catalog.indexes, True,
+ 'space not stripped in add index')
+ self.assertEqual('space' in catalog.indexes, True,
+ 'stripping space in add index failed')
+ i = catalog.indexes['space']
+ # Note: i.id still has spaces in it.
+ self.assert_(isinstance(i, KeywordIndex))
+
def test_del_field_index(self):
catalog = self._make_one()
idx = FieldIndex('id')
More information about the checkins
mailing list