Merge "validate non-ascii values for swift properties"

This commit is contained in:
Jenkins 2015-11-12 22:38:58 +00:00 committed by Gerrit Code Review
commit 6e1ad73723
2 changed files with 16 additions and 0 deletions

View File

@ -14,6 +14,7 @@
"""Object Store v1 API Library""" """Object Store v1 API Library"""
import io import io
import logging
import os import os
import six import six
@ -25,6 +26,7 @@ except ImportError:
from urlparse import urlparse # noqa from urlparse import urlparse # noqa
from openstackclient.api import api from openstackclient.api import api
from openstackclient.common import utils
class APIv1(api.BaseAPI): class APIv1(api.BaseAPI):
@ -551,8 +553,14 @@ class APIv1(api.BaseAPI):
# property we use: "X-Add-Container-Meta-Book: MobyDick", and the same # property we use: "X-Add-Container-Meta-Book: MobyDick", and the same
# logic applies for Object properties # logic applies for Object properties
log = logging.getLogger(__name__ + '._set_properties')
headers = {} headers = {}
for k, v in properties.iteritems(): for k, v in properties.iteritems():
if not utils.is_ascii(k) or not utils.is_ascii(v):
log.error('Cannot set property %s to non-ascii value', k)
continue
header_name = header_tag % k header_name = header_tag % k
headers[header_name] = v headers[header_name] = v
return headers return headers

View File

@ -419,3 +419,11 @@ def build_kwargs_dict(arg_name, value):
if value: if value:
kwargs[arg_name] = value kwargs[arg_name] = value
return kwargs return kwargs
def is_ascii(string):
try:
string.decode('ascii')
return True
except UnicodeDecodeError:
return False