Commit f431bdb9 authored by Alexandre Fayolle's avatar Alexandre Fayolle
Browse files

work around Apache's mod_proxy limitation with special chars in URLs by not...

work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected

--HG--
branch : stable
parent a0fde9334dd0
......@@ -51,6 +51,18 @@ def greater_card(rschema, subjtypes, objtypes, index):
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 @@ class Entity(AppObject):
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:
......
......@@ -492,8 +492,14 @@ du :eid:`1:*ReST*`'''
# 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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment