Beispiel #1
0
    def test_urls_stripped(self):
        # Link with markup. Link text is preserved because it doesn't contain
        # an URL.
        value = 'a <a href="http://example.com">link</a> with markup'
        translation = NoURLsTranslation(localized_string=value)
        assert str(translation) == 'a <a href="">link</a> with markup'

        # Link with markup but this time the text is also an URL. It's stripped
        value = 'a <a href="http://example.com">example.com</a> with markup'
        translation = NoURLsTranslation(localized_string=value)
        assert str(translation) == 'a <a href=""></a> with markup'

        # Text link.
        s = 'a text http://example.com link'
        translation = NoURLsTranslation(localized_string=s)
        assert str(translation) == 'a text  link'

        # Test less obvious link
        s = 'a text foo.is link'
        translation = NoURLsTranslation(localized_string=s)
        assert str(translation) == 'a text  link'

        # Another.
        s = 'a text t.to link'
        translation = NoURLsTranslation(localized_string=s)
        assert str(translation) == 'a text  link'
Beispiel #2
0
 def test_with_newlines(self):
     value = (
         'a <a href="http://example.com">link</a> with markup \n, a text '
         'http://example.com link, and some raw <b>HTML</b>. I <3 http!')
     translation = NoURLsTranslation(localized_string=value)
     assert str(translation) == (
         'a <a href="">link</a> with markup \n, a text '
         ' link, and some raw <b>HTML</b>. I <3 http!')
Beispiel #3
0
 def test_uppercase(self):
     value = (
         'a <a href="http://example.com">link</a> with markup, a text '
         'http://example.com link, and some raw <b>html://</b>. I <3 HTTP!')
     translation = NoURLsTranslation(localized_string=value)
     assert str(translation) == (
         'a <a href="">link</a> with markup, a text '
         ' link, and some raw <b>html://</b>. I <3 HTTP!')
Beispiel #4
0
 def test_bit_of_everything(self):
     value = (
         'a <a href="http://example.com">link</a> with markup,\n'
         'a newline with a more complex link <a href="http://foo.is">lol.com</a>,\n'
         'another http://example.com link, <b>with forbidden tags</b>,\n'
         'and <script>forbidden tags</script> as well as <http:/bad.markup.com'
     )
     translation = NoURLsTranslation(localized_string=value)
     assert str(translation) == (
         'a <a href="">link</a> with markup,\n'
         'a newline with a more complex link <a href=""></a>,\n'
         'another  link, <b>with forbidden tags</b>,\n'
         'and <script>forbidden tags</script> as well as <')
Beispiel #5
0
 def test_no_escaping(self):
     # HTML is not escaped by this model as this is just storing as text.
     value = '<script>some naughty xss</script> & <b>bold</b>'
     translation = NoURLsTranslation(localized_string=value)
     assert str(translation) == str(value)