File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 1
1
# coding: utf-8
2
-
3
2
from django import VERSION as DJANGO_VERSION
4
3
from django import template
5
4
from django .contrib .admin .templatetags .admin_static import static
8
7
from django .utils .safestring import mark_safe
9
8
10
9
from filebrowser .settings import EXTENSIONS , SELECT_FORMATS
11
-
10
+ from filebrowser . utils import json_for_script
12
11
13
12
register = template .Library ()
14
13
@@ -155,7 +154,7 @@ def get_file_extensions(qs):
155
154
for item in v :
156
155
if item :
157
156
extensions .append (item )
158
- return mark_safe (extensions )
157
+ return json_for_script (extensions )
159
158
160
159
161
160
# Django 1.9 auto escapes simple_tag unless marked as safe
Original file line number Diff line number Diff line change 4
4
import os
5
5
import unicodedata
6
6
import math
7
+ import json
7
8
8
9
from django .utils import six
9
10
from django .utils .module_loading import import_string
11
+ from django .utils .html import format_html
12
+ from django .utils .safestring import mark_safe
10
13
11
14
from filebrowser .settings import STRICT_PIL , NORMALIZE_FILENAME , CONVERT_FILENAME
12
15
from filebrowser .settings import VERSION_PROCESSORS
19
22
except ImportError :
20
23
import Image
21
24
25
+ _json_script_escapes = {
26
+ ord ('>' ): '\\ u003E' ,
27
+ ord ('<' ): '\\ u003C' ,
28
+ ord ('&' ): '\\ u0026' ,
29
+ }
30
+
31
+
32
+ def json_for_script (value ):
33
+ """
34
+ Implementation of json_script from Django 2.1
35
+ https://github.com/django/django/commit/8c709d79cbd1a7bb975f58090c17a1178a0efb80
36
+
37
+ If get_file_extensions is a list of unicode characters, JavaScript is unable to handle it and it will break upload.html
38
+ This will convert a list of unicode characters into a regular list, mark it safe, and will escape allthe HTML/XML special
39
+ characters with their unicode escapes
40
+ """
41
+ from django .core .serializers .json import DjangoJSONEncoder
42
+ json_str = json .dumps (value , cls = DjangoJSONEncoder )
43
+ return format_html (
44
+ '{}' ,
45
+ mark_safe (json_str )
46
+ )
47
+
22
48
23
49
def convert_filename (value ):
24
50
"""
You can’t perform that action at this time.
0 commit comments