Chris McDonough
2011-11-18 28f21cd9979f30f510bd6c727fc9f7c6c90dee6d
- Backport fix from master: ``request.static_url`` now generates URL-quoted
URLs when fed a ``path`` argument which contains characters that are
unsuitable for URLs. See https://github.com/Pylons/pyramid/issues/349 for
more information.

- Backport from master: fix ``request.json_body`` to deal with alternate
request charsets.

Ref: issue #349.
7 files modified
67 ■■■■ changed files
CHANGES.txt 13 ●●●●● patch | view | raw | blame | history
pyramid/config/views.py 3 ●●●● patch | view | raw | blame | history
pyramid/request.py 2 ●●● patch | view | raw | blame | history
pyramid/tests/test_config/test_views.py 21 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_request.py 8 ●●●● patch | view | raw | blame | history
pyramid/traversal.py 2 ●●● patch | view | raw | blame | history
tox.ini 18 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -18,6 +18,19 @@
  and can still be used when a path is encoded.  See
  https://github.com/Pylons/pyramid/issues/349 for more information.
- Backport fix from master: ``request.static_url`` now generates URL-quoted
  URLs when fed a ``path`` argument which contains characters that are
  unsuitable for URLs.  See https://github.com/Pylons/pyramid/issues/349 for
  more information.
- Backport from master: fix ``request.json_body`` to deal with alternate
  request charsets.
Testing
-------
- Make tox use WebOb 1.1 for Python 2.5-based systems (WebOb 1.2 is 2.6+).
1.2.1 (2011-09-28)
==================
pyramid/config/views.py
@@ -1,6 +1,7 @@
import inspect
from urlparse import urljoin
from urlparse import urlparse
import urllib
from zope.interface import Interface
from zope.interface import classProvides
@@ -1421,7 +1422,7 @@
            registry = get_current_registry()
        for (url, spec, route_name) in self._get_registrations(registry):
            if path.startswith(spec):
                subpath = path[len(spec):]
                subpath = urllib.quote(path[len(spec):])
                if url is None:
                    kw['subpath'] = subpath
                    return request.route_url(route_name, **kw)
pyramid/request.py
@@ -365,7 +365,7 @@
    @property
    def json_body(self):
        return json.loads(self.body, encoding=self.charset)
        return json.loads(self.body.decode(self.charset))
def route_request_iface(name, bases=()):
    # zope.interface treats the __name__ as the __doc__ and changes __name__
pyramid/tests/test_config/test_views.py
@@ -3346,6 +3346,27 @@
        result = inst.generate('package:path/abc', request, a=1)
        self.assertEqual(result, 'url')
    def test_generate_url_quoted_local(self):
        inst = self._makeOne()
        registrations = [(None, 'package:path/', '__viewname/')]
        inst._get_registrations = lambda *x: registrations
        def route_url(n, **kw):
            self.assertEqual(n, '__viewname/')
            self.assertEqual(kw, {'subpath':'abc%20def', 'a':1})
            return 'url'
        request = self._makeRequest()
        request.route_url = route_url
        result = inst.generate('package:path/abc def', request, a=1)
        self.assertEqual(result, 'url')
    def test_generate_url_quoted_remote(self):
        inst = self._makeOne()
        registrations = [('http://example.com/', 'package:path/', None)]
        inst._get_registrations = lambda *x: registrations
        request = self._makeRequest()
        result = inst.generate('package:path/abc def', request, a=1)
        self.assertEqual(result, 'http://example.com/abc%20def')
    def test_add_already_exists(self):
        inst = self._makeOne()
        config = self._makeConfig(
pyramid/tests/test_request.py
@@ -246,11 +246,11 @@
    def test_json_body_alternate_charset(self):
        from pyramid.compat import json
        request = self._makeOne({'REQUEST_METHOD':'POST'})
        request.charset = 'latin-1'
        la = unicode('La Pe\xc3\xb1a', 'utf-8')
        body = json.dumps({'a':la}, encoding='latin-1')
        inp ='/\xe6\xb5\x81\xe8\xa1\x8c\xe8\xb6\x8b\xe5\x8a\xbf'.decode('utf-8')
        body = json.dumps({'a':inp}).decode('utf-8').encode('utf-16')
        request.body = body
        self.assertEqual(request.json_body, {'a':la})
        request.content_type = 'application/json; charset=utf-16'
        self.assertEqual(request.json_body, {'a':inp})
    def test_json_body_GET_request(self):
        request = self._makeOne({'REQUEST_METHOD':'GET'})
pyramid/traversal.py
@@ -489,7 +489,7 @@
    """
    try:
        path = path.decode('utf-8')
    except UnicodeDecodeError as e:
    except UnicodeDecodeError, e:
        raise URLDecodeError(e.encoding, e.object, e.start, e.end, e.reason)
    path = path.strip('/')
    clean = []
tox.ini
@@ -11,9 +11,25 @@
    repoze.sphinx.autointerface
    virtualenv
[testenv:py25]
commands =
    python setup.py test -q
deps =
    https://github.com/Pylons/webob/zipball/1.1-branch
    Sphinx
    WebTest
    repoze.sphinx.autointerface
    virtualenv
[testenv:jython]
commands = 
   jython setup.py test -q
    jython setup.py test -q
deps =
    https://github.com/Pylons/webob/zipball/1.1-branch
    Sphinx
    WebTest
    repoze.sphinx.autointerface
    virtualenv
[testenv:cover]
basepython =