File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 2020)
2121
2222
23+
2324class TestJson2xml :
2425 """Tests for `json2xml` package."""
2526
@@ -229,3 +230,26 @@ def test_encoding_without_pretty_print(self) -> None:
229230 xmldata = json2xml .Json2xml (data , pretty = False ).to_xml ()
230231 if xmldata :
231232 assert b'encoding="UTF-8"' in xmldata
233+
234+ def test_escapes_angle_brackets (self ):
235+ json_data = json .dumps ({"root" : {"@attrs" : {"HelpText" : "version <here>" }}})
236+ result = json2xml .Json2xml (json_data ).to_xml ()
237+ assert 'HelpText="version <here>"' in result
238+
239+ def test_escapes_quotes (self ):
240+ json_data = json .dumps ({"root" : {"@attrs" : {"Text" : "\" quoted\" " }}})
241+ result = json2xml .Json2xml (json_data ).to_xml ()
242+ assert 'Text=""quoted""' in result
243+
244+ def test_escapes_ampersands (self ):
245+ json_data = json .dumps ({"root" : {"@attrs" : {"Text" : "this & that" }}})
246+ result = json2xml .Json2xml (json_data ).to_xml ()
247+ assert 'Text="this & that"' in result
248+
249+ def test_escapes_mixed_special_chars (self ):
250+ json_data = json .dumps ({"root" : {"@attrs" : {"Text" : "<tag> & \" quote\" " }}})
251+ result = json2xml .Json2xml (json_data ).to_xml ()
252+ assert 'Text="<tag> & "quote""' in result
253+
254+
255+
You can’t perform that action at this time.
0 commit comments