allura
リビジョン | eff488577636f9406db8fec9e6992cb2d5d96b0a (tree) |
---|---|
日時 | 2012-05-15 00:02:36 |
作者 | Cory Johns <johnsca@geek...> |
コミッター | Yaroslav Luzin |
[#4193] Fixed unicode and quoting issue in attachments and added tests
Signed-off-by: Cory Johns <johnsca@geek.net>
@@ -51,7 +51,7 @@ class AttachmentController(BaseController): | ||
51 | 51 | if attachment is None: |
52 | 52 | raise exc.HTTPNotFound |
53 | 53 | return attachment |
54 | - | |
54 | + | |
55 | 55 | @expose() |
56 | 56 | def index(self, delete=False, **kw): |
57 | 57 | if request.method == 'POST': |
@@ -64,8 +64,8 @@ class AttachmentController(BaseController): | ||
64 | 64 | except exc.HTTPNotFound: |
65 | 65 | pass |
66 | 66 | redirect(request.referer) |
67 | - return self.attachment.serve(False) | |
67 | + return self.attachment.serve(embed=False) | |
68 | 68 | |
69 | 69 | @expose() |
70 | - def thumb(self, embed=True): | |
71 | - return self.thumbnail.serve(embed) | |
70 | + def thumb(self): | |
71 | + return self.thumbnail.serve(embed=True) |
@@ -94,7 +94,7 @@ class File(MappedClass): | ||
94 | 94 | if not embed: |
95 | 95 | pylons.response.headers.add( |
96 | 96 | 'Content-Disposition', |
97 | - 'attachment;filename=%s' % self.filename) | |
97 | + 'attachment;filename="%s"' % self.filename.encode('utf-8')) | |
98 | 98 | return iter(fp) |
99 | 99 | |
100 | 100 | @classmethod |
@@ -125,7 +125,7 @@ class TestAttachment(TestController): | ||
125 | 125 | for f in thread.html.findAll('form'): |
126 | 126 | if f.get('action', '').endswith('/post'): |
127 | 127 | break |
128 | - self.post_form_link = f['action'].encode('utf-8') | |
128 | + self.post_form_link = f['action'].encode('utf-8') | |
129 | 129 | params = dict() |
130 | 130 | inputs = f.findAll('input') |
131 | 131 | for field in inputs: |
@@ -148,6 +148,7 @@ class TestAttachment(TestController): | ||
148 | 148 | else: |
149 | 149 | assert False, 'attachment link not found' |
150 | 150 | r = self.app.get(alink) |
151 | + assert r.content_disposition == 'attachment;filename="test.txt"', 'Attachments should force download' | |
151 | 152 | r = self.app.post(self.post_link + 'attach', |
152 | 153 | upload_files=[('file_info', 'test.o12', 'HiThere!')]) |
153 | 154 | r = self.app.post(alink, params=dict(delete='on')) |
@@ -100,7 +100,7 @@ class TestFile(TestCase): | ||
100 | 100 | self._assert_content(f, 'test2') |
101 | 101 | |
102 | 102 | def test_serve(self): |
103 | - f = File.from_data('test1.txt', 'test1') | |
103 | + f = File.from_data(u'te s\u0b6e1.txt', 'test1') | |
104 | 104 | self.session.flush() |
105 | 105 | assert [ 'test1' ] == list(f.serve()) |
106 | 106 | assert response.content_type == f.content_type |
@@ -108,7 +108,7 @@ class TestFile(TestCase): | ||
108 | 108 | assert [ 'test1' ] == list(f.serve(False)) |
109 | 109 | assert response.content_type == f.content_type |
110 | 110 | assert response.headers['Content-Disposition'] == \ |
111 | - 'attachment;filename=test1.txt' | |
111 | + 'attachment;filename="te s\xe0\xad\xae1.txt"' | |
112 | 112 | |
113 | 113 | def test_image(self): |
114 | 114 | path = os.path.join( |