Commit f0c25c0b authored by Martijn Pieters's avatar Martijn Pieters

Backport fix for 2288, together with part of the 2.10 tests for z3 views

parent 1f7195aa
...@@ -8,6 +8,9 @@ Zope Changes ...@@ -8,6 +8,9 @@ Zope Changes
Bugs fixed Bugs fixed
- Collector #2288: @ and + should not be quoted when forming
request URLs in BaseRequest and HTTPRequest
- Undeprectated 'zLOG' package, which is going to remain a - Undeprectated 'zLOG' package, which is going to remain a
backward-compatibility shim for the Python logger. backward-compatibility shim for the Python logger.
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
$Id$ $Id$
""" """
from urllib import quote from urllib import quote as urllib_quote
import xmlrpc import xmlrpc
from zExceptions import Forbidden from zExceptions import Forbidden
...@@ -23,6 +23,10 @@ from zope.app.publication.interfaces import EndRequestEvent ...@@ -23,6 +23,10 @@ from zope.app.publication.interfaces import EndRequestEvent
UNSPECIFIED_ROLES='' UNSPECIFIED_ROLES=''
def quote(text):
# quote url path segments, but leave + and @ intact
return urllib_quote(text, '/+@')
try: try:
from ExtensionClass import Base from ExtensionClass import Base
class RequestContainer(Base): class RequestContainer(Base):
......
...@@ -15,10 +15,10 @@ __version__='$Revision: 1.96 $'[11:-2] ...@@ -15,10 +15,10 @@ __version__='$Revision: 1.96 $'[11:-2]
import re, sys, os, time, random, codecs import re, sys, os, time, random, codecs
from types import StringType, UnicodeType from types import StringType, UnicodeType
from BaseRequest import BaseRequest from BaseRequest import BaseRequest, quote
from HTTPResponse import HTTPResponse from HTTPResponse import HTTPResponse
from cgi import FieldStorage, escape from cgi import FieldStorage, escape
from urllib import quote, unquote, splittype, splitport from urllib import unquote, splittype, splitport
from copy import deepcopy from copy import deepcopy
from Converters import get_converter from Converters import get_converter
from TaintedString import TaintedString from TaintedString import TaintedString
......
...@@ -248,6 +248,76 @@ class TestBaseRequest(TestCase): ...@@ -248,6 +248,76 @@ class TestBaseRequest(TestCase):
self.assertRaises(NotFound, r.traverse, 'folder/simpleFrozenSet') self.assertRaises(NotFound, r.traverse, 'folder/simpleFrozenSet')
import zope.interface
import zope.component
import zope.testing.cleanup
import zope.app.traversing.namespace
from zope.publisher.browser import IBrowserRequest
from zope.publisher.browser import IDefaultBrowserLayer
from zope.app.traversing.interfaces import ITraversable
class IDummy(zope.interface.Interface):
"""IDummy"""
class DummyObjectZ3(DummyObjectBasic):
zope.interface.implements(IDummy)
def __init__(self, name):
self.name = name
class DummyView(Implicit):
def __init__(self, content, request):
self.content = content
self.request = request
def __call__(self):
return 'view on %s' % (self.content.name)
class TestBaseRequestZope3Views(TestCase):
def setUp(self):
zope.testing.cleanup.cleanUp()
self.root = DummyObjectBasic()
folder = self.root._setObject('folder', DummyObjectZ3('folder'))
folder._setObject('obj', DummyObjectZ3('obj'))
gsm = zope.component.getGlobalSiteManager()
# The request needs to implement the proper interface
zope.interface.classImplements(BaseRequest, IDefaultBrowserLayer)
# Define our 'meth' view
gsm.registerAdapter(DummyView, (IDummy, IDefaultBrowserLayer), None,
'meth')
# Bind the 'view' namespace (for @@ traversal)
gsm.registerAdapter(zope.traversing.namespace.view,
(IDummy, IDefaultBrowserLayer), ITraversable,
'view')
def tearDown(self):
zope.testing.cleanup.cleanUp()
def makeBaseRequest(self):
response = HTTPResponse()
environment = {
'URL': '',
'PARENTS': [self.root],
'steps': [],
'_hacked_path': 0,
'_test_counter': 0,
'response': response,
}
return BaseRequest(environment)
def test_quoting(self):
"""View markers should not be quoted"""
r = self.makeBaseRequest()
r.traverse('folder/obj/@@meth')
self.assertEqual(r['URL'], '/folder/obj/@@meth')
r = self.makeBaseRequest()
r.traverse('folder/obj/++view++meth')
self.assertEqual(r['URL'], '/folder/obj/++view++meth')
def test_suite(): def test_suite():
return TestSuite( ( makeSuite(TestBaseRequest), ) ) return TestSuite( ( makeSuite(TestBaseRequest), ) )
......
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