diff --git a/swift/common/middleware/staticweb.py b/swift/common/middleware/staticweb.py index 8874096beb..8a2061cb17 100644 --- a/swift/common/middleware/staticweb.py +++ b/swift/common/middleware/staticweb.py @@ -125,13 +125,17 @@ from swift.common.swob import Response, HTTPMovedPermanently, HTTPNotFound from swift.proxy.controllers.base import get_container_info +def ensure_utf8_bytes(value): + if isinstance(value, unicode): + value = value.encode('utf-8') + return value + + 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) + return urllib_quote(ensure_utf8_bytes(value), safe) class _StaticWebContext(WSGIContext): @@ -272,10 +276,7 @@ class _StaticWebContext(WSGIContext): ' \n' for item in listing: if 'subdir' in item: - if isinstance(item['subdir'], unicode): - subdir = item['subdir'].encode('utf-8') - else: - subdir = item['subdir'] + subdir = ensure_utf8_bytes(item['subdir']) if prefix: subdir = subdir[len(prefix):] body += '