File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -261,8 +261,14 @@ def to_json(dict_: dict, pretty: bool = False) -> str:
261261 else :
262262 indent = None
263263
264- return json .dumps (dict_ , default = json_serial , indent = indent ,
265- separators = (',' , ':' ))
264+ LOGGER .debug ('Dumping JSON' )
265+ json_dump = json .dumps (dict_ , default = json_serial , indent = indent ,
266+ separators = (',' , ':' ))
267+
268+ LOGGER .debug ('Removing < and >' )
269+ json_dump = json_dump .replace ('<' , '<' ).replace ('>' , '>' )
270+
271+ return json_dump
266272
267273
268274def format_datetime (value : str , format_ : str = DATETIME_FORMAT ) -> str :
Original file line number Diff line number Diff line change @@ -74,6 +74,17 @@ def test_get_typed_value():
7474 assert isinstance (value , bool )
7575
7676
77+ @pytest .mark .parametrize ('data,minified,pretty_printed' , [
78+ [{'foo' : 'bar' }, '{"foo":"bar"}' , '{\n "foo":"bar"\n }' ],
79+ [{'foo<script>alert("hi")</script>' : 'bar' },
80+ '{"foo<script>alert(\\ "hi\\ ")</script>":"bar"}' ,
81+ '{\n "foo<script>alert(\\ "hi\\ ")</script>":"bar"\n }' ]
82+ ])
83+ def test_to_json (data , minified , pretty_printed ):
84+ assert util .to_json (data ) == minified
85+ assert util .to_json (data , pretty = True ) == pretty_printed
86+
87+
7788def test_yaml_load (config ):
7889 assert isinstance (config , dict )
7990 with pytest .raises (FileNotFoundError ):
You can’t perform that action at this time.
0 commit comments