thumbnails: Handle non-ASCII filenames
The WSGI specification requires that URL-paths be encoded as ISO-8859-1 (Latin-1). For filenames that only use ASCII characters, this works correctly. When a filename includes characters encoded in other character sets, however, the thumbnail controller will return always HTTP 404 if the local filesystem does not also use the Latin-1 character set. To work around this discrepancy and ensure that requested file names are looked up on the local filesystem correctly, the string must be re-encoded in the proper character set.master
parent
15719c20b5
commit
607d3120f6
|
@ -3,6 +3,10 @@ from milla import controllers
|
|||
import milla
|
||||
import os
|
||||
import webob.static
|
||||
import sys
|
||||
|
||||
|
||||
fs_encoding = sys.getfilesystemencoding()
|
||||
|
||||
|
||||
class ThumbnailController(milla.controllers.HTTPVerbController):
|
||||
|
@ -11,6 +15,7 @@ class ThumbnailController(milla.controllers.HTTPVerbController):
|
|||
THUMB_SIZE = (262, 148)
|
||||
|
||||
def GET(self, request, image):
|
||||
image = image.encode('latin-1').decode(fs_encoding)
|
||||
thumb_dir = request.config['gallery.thumbnail_dir']
|
||||
image_dir = request.config['gallery.screenshot_dir']
|
||||
screenshot = os.path.join(image_dir, image)
|
||||
|
|
Loading…
Reference in New Issue