Sha256: e97e0735b7e7b83d0e7d49b9c05f91928514aedad1ae6e5e591530c6d363c383

Contents?: true

Size: 1.05 KB

Versions: 33

Compression:

Stored size: 1.05 KB

Contents

import unittest

import simplejson.decoder
import simplejson.encoder


class TestEncodeForHTML(unittest.TestCase):

    def setUp(self):
        self.decoder = simplejson.decoder.JSONDecoder()
        self.encoder = simplejson.encoder.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)))

Version data entries

33 entries across 33 versions & 5 rubygems

Version Path
pygments.rb-1.2.1 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-1.2.0 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-1.1.2 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-1.1.1 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-1.1.0 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-1.0.0 vendor/simplejson/simplejson/tests/test_encode_for_html.py
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/pygments.rb-0.6.3/vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-0.6.3 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-0.6.2 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-0.6.1 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-0.6.0 vendor/simplejson/simplejson/tests/test_encode_for_html.py
mortar-pygments.rb-0.5.7 vendor/simplejson/simplejson/tests/test_encode_for_html.py
mortar-pygments.rb-0.5.6 vendor/simplejson/simplejson/tests/test_encode_for_html.py
mortar-pygments.rb-0.5.5 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-jruby-0.5.4.2 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-jruby-0.5.4.1 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-jruby-0.5.4 vendor/simplejson/simplejson/tests/test_encode_for_html.py
gitlab-pygments.rb-0.5.4 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-0.5.4 vendor/simplejson/simplejson/tests/test_encode_for_html.py
pygments.rb-0.5.2 vendor/simplejson/simplejson/tests/test_encode_for_html.py