# HG changeset patch # User Alexandre Fayolle # Date 1281534884 -7200 # Node ID b22a4a3895df3f5ee3416803d73f8327176233e1 # Parent a0fde9334dd04ee0ea7bf6beef8f3e59df1352ed work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected diff -r a0fde9334dd0 -r b22a4a3895df entity.py --- a/entity.py Wed Aug 11 16:17:05 2010 +0200 +++ b/entity.py Wed Aug 11 15:54:44 2010 +0200 @@ -51,6 +51,18 @@ return card return '1' +def can_use_rest_path(value): + """return True if value can be used at the end of a Rest URL path""" + if value is None: + return False + value = unicode(value) + # the check for ?, /, & are to prevent problems when running + # behind Apache mod_proxy + if value == u'' or u'?' in value or u'/' in value or u'&' in value: + return False + return True + + class Entity(AppObject): """an entity instance has e_schema automagically set on @@ -502,7 +514,7 @@ path = etype.lower() if mainattr != 'eid': value = getattr(self, mainattr) - if value is None or unicode(value) == u'': + if not can_use_rest_path(value): mainattr = 'eid' path += '/eid' elif needcheck: diff -r a0fde9334dd0 -r b22a4a3895df test/unittest_entity.py --- a/test/unittest_entity.py Wed Aug 11 16:17:05 2010 +0200 +++ b/test/unittest_entity.py Wed Aug 11 15:54:44 2010 +0200 @@ -492,8 +492,14 @@ # unique attr with None value (wikiid in this case) card1 = req.create_entity('Card', title=u'hop') self.assertEquals(card1.rest_path(), 'card/eid/%s' % card1.eid) - card2 = req.create_entity('Card', title=u'pod', wikiid=u'zob/i') - self.assertEquals(card2.rest_path(), 'card/zob%2Fi') + # don't use rest if we have /, ? or & in the path (breaks mod_proxy) + card2 = req.create_entity('Card', title=u'pod', wikiid=u'zo/bi') + self.assertEquals(card2.rest_path(), 'card/eid/%d' % card2.eid) + card3 = req.create_entity('Card', title=u'pod', wikiid=u'zo&bi') + self.assertEquals(card3.rest_path(), 'card/eid/%d' % card3.eid) + card4 = req.create_entity('Card', title=u'pod', wikiid=u'zo?bi') + self.assertEquals(card4.rest_path(), 'card/eid/%d' % card4.eid) + def test_set_attributes(self): req = self.request()