Skip to content

Commit 94e9162

Browse files
committed
Merge branch 'feature/multipart_reader' of github.com:SunRunAway/python-sdk into feature/multipart_reader
2 parents fa0b457 + a73b91c commit 94e9162

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

qiniu/rpc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def encode_multipart_formdata(self, fields, files):
110110
L.append('')
111111
L.append('--' + BOUNDARY)
112112
disposition = "Content-Disposition: form-data;"
113-
L.append('%s name="file"; filename="%s"' % (disposition, file_info.get('filename')))
113+
filename = _qiniu_escape(file_info.get('filename'))
114+
L.append('%s name="file"; filename="%s"' % (disposition, filename))
114115
L.append('Content-Type: %s' % file_info.get('content_type', 'application/octet-stream'))
115116
L.append('')
116117
L.append('')
@@ -127,6 +128,12 @@ def encode_multipart_formdata(self, fields, files):
127128
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
128129
return content_type, MultiReader(readers)
129130

131+
def _qiniu_escape(s):
132+
edits = [('\\', '\\\\'), ('\"', '\\\"')]
133+
for (search, replace) in edits:
134+
s = s.replace(search, replace)
135+
return s
136+
130137

131138
class MultiReader(object):
132139
""" class MultiReader([readers...])

qiniu/test/io_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ def test_put_no_key():
5454
assert err is None
5555
assert ret['hash'] == ret['key']
5656

57+
def test_put_quote_key():
58+
data = r(100)
59+
key = 'a\\b\\c"你好' + r(9)
60+
ret, err = io.put(policy.token(), key, data)
61+
print err
62+
assert err is None
63+
assert ret['key'].encode('utf8') == key
64+
65+
data = r(100)
66+
key = u'a\\b\\c"你好' + r(9)
67+
ret, err = io.put(policy.token(), key, data)
68+
assert err is None
69+
assert ret['key'] == key
70+
5771
def test_put_unicode1():
5872
key = "test_%s" % r(9) + '你好'
5973
data = key
@@ -125,6 +139,7 @@ def read(self, n=None):
125139
test_put()
126140
test_put_same_crc()
127141
test_put_no_key()
142+
test_put_quote_key()
128143
test_put_unicode1()
129144
test_put_unicode2()
130145
test_put_unicode3()

0 commit comments

Comments
 (0)