Skip to content

Commit ec886f1

Browse files
committed
Fix upload invalid SVG file
1 parent c71e4d3 commit ec886f1

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

filer/templates/admin/filer/folder/directory_table.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
{{ file.owner|default:"n/a" }}
133133
</td>
134134
<td class="column-size">
135-
<span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% ifequal file.file_type "Image" %}, {{ file.width|floatformat }}x{{ file.height|floatformat }} px{% endifequal %})</span>
135+
<span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% if file.file_type == "Image" and file.width > 0.0 and file.height > 0.0 %}, {{ file.width|floatformat }}x{{ file.height|floatformat }} px{% endif %})</span>
136136
</td>
137137
<td class="column-action">
138138
<a href="{{ file.canonical_url }}"

filer/templatetags/filer_admin_tags.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,23 @@ def file_icon_context(file, detail, width, height):
7979
context['download_url'] = file.url
8080
if isinstance(file, BaseImage):
8181
thumbnailer = get_thumbnailer(file)
82-
if detail:
83-
width, height = 210, ceil(210 / file.width * file.height)
84-
context['sidebar_image_ratio'] = file.width / 210
85-
opts = {'size': (width, height), 'upscale': True}
82+
83+
# SVG files may contain multiple vector graphics, and width and height are not available for them. If file does
84+
# not have width or height just ignore the thumbnail icon. Otherwise, continue with the standard procedure.
85+
if file.width == 0.0 or file.height == 0.0:
86+
icon_url = staticfiles_storage.url('filer/icons/file-unknown.svg')
8687
else:
87-
opts = {'size': (width, height), 'crop': True}
88-
icon_url = thumbnailer.get_thumbnail(opts).url
89-
context['alt_text'] = file.default_alt_text
90-
if mime_subtype != 'svg+xml':
91-
opts['size'] = 2 * width, 2 * height
92-
context['highres_url'] = thumbnailer.get_thumbnail(opts).url
88+
if detail:
89+
width, height = 210, ceil(210 / file.width * file.height)
90+
context['sidebar_image_ratio'] = file.width / 210
91+
opts = {'size': (width, height), 'upscale': True}
92+
else:
93+
opts = {'size': (width, height), 'crop': True}
94+
icon_url = thumbnailer.get_thumbnail(opts).url
95+
context['alt_text'] = file.default_alt_text
96+
if mime_subtype != 'svg+xml':
97+
opts['size'] = 2 * width, 2 * height
98+
context['highres_url'] = thumbnailer.get_thumbnail(opts).url
9399
elif mime_maintype in ['audio', 'font', 'video']:
94100
icon_url = staticfiles_storage.url('filer/icons/file-{}.svg'.format(mime_maintype))
95101
elif mime_maintype == 'application' and mime_subtype in ['zip', 'pdf']:

0 commit comments

Comments
 (0)