Make check_xml_encodable to only validate utf-8 correctness
This commit is contained in:
@@ -32,7 +32,7 @@ from swift.common.db import AccountBroker
|
||||
from swift.common.utils import get_logger, get_param, hash_path, \
|
||||
normalize_timestamp, split_path, storage_directory
|
||||
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
|
||||
check_mount, check_float, check_xml_encodable
|
||||
check_mount, check_float, check_utf8
|
||||
from swift.common.db_replicator import ReplicatorRpc
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ class AccountController(object):
|
||||
def __call__(self, env, start_response):
|
||||
start_time = time.time()
|
||||
req = Request(env)
|
||||
if not check_xml_encodable(req.path_info):
|
||||
if not check_utf8(req.path_info):
|
||||
res = HTTPPreconditionFailed(body='Invalid UTF8')
|
||||
else:
|
||||
try:
|
||||
|
@@ -108,7 +108,7 @@ def check_object_creation(req, object_name):
|
||||
if 'Content-Type' not in req.headers:
|
||||
return HTTPBadRequest(request=req, content_type='text/plain',
|
||||
body='No content type')
|
||||
if not check_xml_encodable(req.headers['Content-Type']):
|
||||
if not check_utf8(req.headers['Content-Type']):
|
||||
return HTTPBadRequest(request=req, body='Invalid Content-Type',
|
||||
content_type='text/plain')
|
||||
return check_metadata(req, 'object')
|
||||
@@ -148,14 +148,15 @@ _invalid_xml = re.compile(ur'[^\x09\x0a\x0d\x20-\uD7FF\uE000-\uFFFD%s-%s]' %
|
||||
(unichr(0x10000), unichr(0x10FFFF)))
|
||||
|
||||
|
||||
def check_xml_encodable(string):
|
||||
def check_utf8(string):
|
||||
"""
|
||||
Validate if a string can be encoded in xml.
|
||||
Validate if a string is valid UTF-8.
|
||||
|
||||
:param string: string to be validated
|
||||
:returns: True if the string can be encoded in xml, False otherwise
|
||||
:returns: True if the string is valid utf-8, False otherwise
|
||||
"""
|
||||
try:
|
||||
return not _invalid_xml.search(string.decode('UTF-8'))
|
||||
string.decode('UTF-8')
|
||||
return True
|
||||
except UnicodeDecodeError:
|
||||
return False
|
||||
|
@@ -33,7 +33,7 @@ from swift.common.db import ContainerBroker
|
||||
from swift.common.utils import get_logger, get_param, hash_path, \
|
||||
normalize_timestamp, storage_directory, split_path
|
||||
from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
|
||||
check_mount, check_float, check_xml_encodable
|
||||
check_mount, check_float, check_utf8
|
||||
from swift.common.bufferedhttp import http_connect
|
||||
from swift.common.exceptions import ConnectionTimeout
|
||||
from swift.common.db_replicator import ReplicatorRpc
|
||||
@@ -386,7 +386,7 @@ class ContainerController(object):
|
||||
def __call__(self, env, start_response):
|
||||
start_time = time.time()
|
||||
req = Request(env)
|
||||
if not check_xml_encodable(req.path_info):
|
||||
if not check_utf8(req.path_info):
|
||||
res = HTTPPreconditionFailed(body='Invalid UTF8')
|
||||
else:
|
||||
try:
|
||||
|
@@ -40,7 +40,7 @@ from swift.common.utils import mkdirs, normalize_timestamp, \
|
||||
split_path, drop_buffer_cache, get_logger
|
||||
from swift.common.bufferedhttp import http_connect
|
||||
from swift.common.constraints import check_object_creation, check_mount, \
|
||||
check_float, check_xml_encodable
|
||||
check_float, check_utf8
|
||||
from swift.common.exceptions import ConnectionTimeout
|
||||
from swift.obj.replicator import get_hashes, invalidate_hash, \
|
||||
recalculate_hashes
|
||||
@@ -557,7 +557,7 @@ class ObjectController(object):
|
||||
"""WSGI Application entry point for the Swift Object Server."""
|
||||
start_time = time.time()
|
||||
req = Request(env)
|
||||
if not check_xml_encodable(req.path_info):
|
||||
if not check_utf8(req.path_info):
|
||||
res = HTTPPreconditionFailed(body='Invalid UTF8')
|
||||
else:
|
||||
try:
|
||||
|
@@ -36,7 +36,7 @@ from swift.common.utils import get_logger, normalize_timestamp, split_path, \
|
||||
cache_from_env
|
||||
from swift.common.bufferedhttp import http_connect
|
||||
from swift.common.constraints import check_metadata, check_object_creation, \
|
||||
check_xml_encodable, MAX_ACCOUNT_NAME_LENGTH, MAX_CONTAINER_NAME_LENGTH, \
|
||||
check_utf8, MAX_ACCOUNT_NAME_LENGTH, MAX_CONTAINER_NAME_LENGTH, \
|
||||
MAX_FILE_SIZE
|
||||
from swift.common.exceptions import ChunkReadTimeout, \
|
||||
ChunkWriteTimeout, ConnectionTimeout
|
||||
@@ -1298,7 +1298,7 @@ class BaseApplication(object):
|
||||
controller, path_parts = self.get_controller(req.path)
|
||||
except ValueError:
|
||||
return HTTPNotFound(request=req)
|
||||
if not check_xml_encodable(req.path_info):
|
||||
if not check_utf8(req.path_info):
|
||||
return HTTPPreconditionFailed(request=req, body='Invalid UTF8')
|
||||
if not controller:
|
||||
return HTTPPreconditionFailed(request=req, body='Bad URL')
|
||||
|
Reference in New Issue
Block a user