[Zope-dev] redirect burps on unicode URLs

Tres Seaver tseaver at palladion.com
Thu Feb 25 11:08:46 EST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Adam GROSZER wrote:
> Hello,
> 
> Looks like zope.publisher burps on unicode URL which contain non-ascii
> chars. This is from a KGS 3.4 application, but looking at the source
> it still seems to have the same problems.
> 
> opinions?
> 
> ...
>     self.request.response.redirect(url)
>   File "d:\home\.buildout\eggs\zope.publisher-3.4.6-py2.5.egg\zope\publisher\browser.py", line
> 729, in redirect
>     return super(BrowserResponse, self).redirect(location, status)
>   File "d:\home\.buildout\eggs\zope.publisher-3.4.6-py2.5.egg\zope\publisher\http.py", line 882,
> in redirect
>     self.setHeader('Location', location)
>   File "d:\home\.buildout\eggs\zope.publisher-3.4.6-py2.5.egg\zope\publisher\http.py", line 676,
> in setHeader
>     value = str(value)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in position 71: ordinal not in
> range(128)

Two issues:

- - Technically there is no such thing as a "unicode URL":  URLs are
  always ASCII, with other characters encoded[1].  IRIs and IRLs are
  a different thing altogether.

- - Headers in responses must *not* be Unicode.

Your application needs to make the URL header-safe before calling
redirect, likely by using 'urlencode'.


[1] http://tools.ietf.org/html/rfc1738#section-2.2



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkuGoI4ACgkQ+gerLs4ltQ5zGACfYBpr0A3z4pnH6qdS/Ku7irjO
Lt4AoIWHrsO3gN6AioJfbjbv1us/mZQf
=5r8C
-----END PGP SIGNATURE-----



More information about the Zope-Dev mailing list