Merge "Fix for UTF-8 encoding/quoting issues in staticweb"
This commit is contained in:
@@ -116,7 +116,7 @@ except ImportError:
|
|||||||
|
|
||||||
import cgi
|
import cgi
|
||||||
import time
|
import time
|
||||||
from urllib import unquote, quote
|
from urllib import unquote, quote as urllib_quote
|
||||||
|
|
||||||
from webob import Response, Request
|
from webob import Response, Request
|
||||||
from webob.exc import HTTPMovedPermanently, HTTPNotFound
|
from webob.exc import HTTPMovedPermanently, HTTPNotFound
|
||||||
@@ -125,6 +125,15 @@ from swift.common.utils import cache_from_env, get_logger, human_readable, \
|
|||||||
split_path, TRUE_VALUES
|
split_path, TRUE_VALUES
|
||||||
|
|
||||||
|
|
||||||
|
def quote(value, safe='/'):
|
||||||
|
"""
|
||||||
|
Patched version of urllib.quote that encodes utf-8 strings before quoting
|
||||||
|
"""
|
||||||
|
if isinstance(value, unicode):
|
||||||
|
value = value.encode('utf-8')
|
||||||
|
return urllib_quote(value, safe)
|
||||||
|
|
||||||
|
|
||||||
class StaticWeb(object):
|
class StaticWeb(object):
|
||||||
"""
|
"""
|
||||||
The Static Web WSGI middleware filter; serves container data as a static
|
The Static Web WSGI middleware filter; serves container data as a static
|
||||||
@@ -289,7 +298,7 @@ class StaticWeb(object):
|
|||||||
if not listing:
|
if not listing:
|
||||||
resp = HTTPNotFound()(env, self._start_response)
|
resp = HTTPNotFound()(env, self._start_response)
|
||||||
return self._error_response(resp, env, start_response)
|
return self._error_response(resp, env, start_response)
|
||||||
headers = {'Content-Type': 'text/html'}
|
headers = {'Content-Type': 'text/html; charset=UTF-8'}
|
||||||
body = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 ' \
|
body = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 ' \
|
||||||
'Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n' \
|
'Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n' \
|
||||||
'<html>\n' \
|
'<html>\n' \
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ class FakeApp(object):
|
|||||||
"hash":"c85c1dcd19cf5cbac84e6043c31bb63e", "bytes":20,
|
"hash":"c85c1dcd19cf5cbac84e6043c31bb63e", "bytes":20,
|
||||||
"content_type":"text/plain",
|
"content_type":"text/plain",
|
||||||
"last_modified":"2011-03-24T04:27:52.734140"},
|
"last_modified":"2011-03-24T04:27:52.734140"},
|
||||||
{"name":"subdir/omgomg.txt",
|
{"name":"subdir/\u2603.txt",
|
||||||
"hash":"7337d028c093130898d937c319cc9865", "bytes":72981,
|
"hash":"7337d028c093130898d937c319cc9865", "bytes":72981,
|
||||||
"content_type":"text/plain",
|
"content_type":"text/plain",
|
||||||
"last_modified":"2011-03-24T04:27:52.735460"},
|
"last_modified":"2011-03-24T04:27:52.735460"},
|
||||||
@@ -290,7 +290,7 @@ class FakeApp(object):
|
|||||||
'Content-Type': 'text/plain; charset=utf-8'})
|
'Content-Type': 'text/plain; charset=utf-8'})
|
||||||
body = '\n'.join(['401error.html', '404error.html', 'index.html',
|
body = '\n'.join(['401error.html', '404error.html', 'index.html',
|
||||||
'listing.css', 'one.txt', 'subdir/1.txt',
|
'listing.css', 'one.txt', 'subdir/1.txt',
|
||||||
'subdir/2.txt', 'subdir/omgomg.txt', 'subdir2',
|
'subdir/2.txt', u'subdir/\u2603.txt', 'subdir2',
|
||||||
'subdir3/subsubdir/index.html', 'two.txt'])
|
'subdir3/subsubdir/index.html', 'two.txt'])
|
||||||
return Response(status='200 Ok', headers=headers,
|
return Response(status='200 Ok', headers=headers,
|
||||||
body=body)(env, start_response)
|
body=body)(env, start_response)
|
||||||
@@ -480,6 +480,8 @@ class TestStaticWeb(unittest.TestCase):
|
|||||||
self.assert_('</style>' not in resp.body)
|
self.assert_('</style>' not in resp.body)
|
||||||
self.assert_('<link' in resp.body)
|
self.assert_('<link' in resp.body)
|
||||||
self.assert_('listing.css' in resp.body)
|
self.assert_('listing.css' in resp.body)
|
||||||
|
self.assertEquals(resp.headers['content-type'],
|
||||||
|
'text/html; charset=UTF-8')
|
||||||
|
|
||||||
def test_container4onetxt(self):
|
def test_container4onetxt(self):
|
||||||
resp = Request.blank(
|
resp = Request.blank(
|
||||||
|
|||||||
Reference in New Issue
Block a user