diff options
author | 2014-09-08 00:30:40 +0200 | |
---|---|---|
committer | 2014-09-14 11:02:52 +0200 | |
commit | 25a6564b42c8e73843b63ca57357a3573ac48c9c (patch) | |
tree | 36d2f2c3edbfa425e945c927757449c0060b18d6 /pyload/lib/simplejson/tests/test_encode_for_html.py | |
parent | module -> pyload (diff) | |
download | pyload-25a6564b42c8e73843b63ca57357a3573ac48c9c.tar.xz |
[Lib] Update simplejson to v3.6.3 + one file wsgiserver + importing fixup
Diffstat (limited to 'pyload/lib/simplejson/tests/test_encode_for_html.py')
-rw-r--r-- | pyload/lib/simplejson/tests/test_encode_for_html.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/pyload/lib/simplejson/tests/test_encode_for_html.py b/pyload/lib/simplejson/tests/test_encode_for_html.py new file mode 100644 index 000000000..f99525486 --- /dev/null +++ b/pyload/lib/simplejson/tests/test_encode_for_html.py @@ -0,0 +1,30 @@ +import unittest + +import simplejson as json + +class TestEncodeForHTML(unittest.TestCase): + + def setUp(self): + self.decoder = json.JSONDecoder() + self.encoder = json.JSONEncoderForHTML() + + def test_basic_encode(self): + self.assertEqual(r'"\u0026"', self.encoder.encode('&')) + self.assertEqual(r'"\u003c"', self.encoder.encode('<')) + self.assertEqual(r'"\u003e"', self.encoder.encode('>')) + + def test_basic_roundtrip(self): + for char in '&<>': + self.assertEqual( + char, self.decoder.decode( + self.encoder.encode(char))) + + def test_prevent_script_breakout(self): + bad_string = '</script><script>alert("gotcha")</script>' + self.assertEqual( + r'"\u003c/script\u003e\u003cscript\u003e' + r'alert(\"gotcha\")\u003c/script\u003e"', + self.encoder.encode(bad_string)) + self.assertEqual( + bad_string, self.decoder.decode( + self.encoder.encode(bad_string))) |