From ef3f8bb335de47439211e3e72835ffa50beb3559 Mon Sep 17 00:00:00 2001 From: gholt Date: Thu, 2 Aug 2012 14:49:02 +0000 Subject: [PATCH] Ensure parameters sent to db are utf8 strs Change-Id: I45952adfcfbc813477ee9966f05dcdeef23c683b --- swift/common/db.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/swift/common/db.py b/swift/common/db.py index 69466a1a15..3245ffcbf2 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -47,6 +47,10 @@ PICKLE_PROTOCOL = 2 PENDING_CAP = 131072 +def utf8encode(*args): + return [(s.encode('utf8') if isinstance(s, unicode) else s) for s in args] + + class DatabaseConnectionError(sqlite3.DatabaseError): """More friendly error messages for DB Errors.""" @@ -1062,6 +1066,8 @@ class ContainerBroker(DatabaseBroker): :returns: list of tuples of (name, created_at, size, content_type, etag) """ + (marker, end_marker, prefix, delimiter, path) = utf8encode( + marker, end_marker, prefix, delimiter, path) try: self._commit_puts() except LockTimeout: @@ -1102,8 +1108,6 @@ class ContainerBroker(DatabaseBroker): if prefix is None: return [r for r in curs] if not delimiter: - if isinstance(prefix, unicode): - prefix = prefix.encode("utf-8") return [r for r in curs if r[0].startswith(prefix)] rowcount = 0 for row in curs: @@ -1557,6 +1561,8 @@ class AccountBroker(DatabaseBroker): :returns: list of tuples of (name, object_count, bytes_used, 0) """ + (marker, end_marker, prefix, delimiter) = utf8encode( + marker, end_marker, prefix, delimiter) try: self._commit_puts() except LockTimeout: