Beispiel #1
0
 def test_external_text_link(self, get_outgoing_url_mock):
     get_outgoing_url_mock.return_value = 'http://external.url'
     s = u'<b>markup</b> http://example.com'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(),
         u'<b>markup</b> <a rel="nofollow" '
         u'href="http://external.url">http://example.com</a>')
Beispiel #2
0
 def test_external_text_link(self):
     s = u'<b>markup</b> http://example.com'
     x = PurifiedTranslation(localized_string=s)
     eq_(
         x.__html__(),
         u'<b>markup</b> <a href="http://example.com">http://example.com</a>'
     )
Beispiel #3
0
 def test_newlines_ul_loose(self):
     before = ("There should be two nl's between this and the ul.\n\n"
               "<ul><li>test</li><li>test</li></ul>\n\n"
               "There should be one nl above this line.")
     after = ("There should be two nl's between this and the ul.\n\n"
              "<ul><li>test</li><li>test</li></ul>\n"
              "There should be one nl above this line.")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #4
0
 def test_newlines_normal(self):
     before = ("Paragraph one.\n"
               "This should be on the very next line.\n\n"
               "Should be two nl's before this line.\n\n\n"
               "Should be three nl's before this line.\n\n\n\n"
               "Should be four nl's before this line.")
     after = before  # Nothing special; this shouldn't change.
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #5
0
 def test_newlines_blockquote_loose(self):
     before = ("There should be two nls below this.\n\n"
               "<blockquote>Hi</blockquote>\n\n"
               "There should be one nl above this.")
     after = ("There should be two nls below this.\n\n"
              "<blockquote>Hi</blockquote>\n"
              "There should be one nl above this.")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #6
0
def test_truncate_purified_field_xss():
    """Truncating should not introduce xss issues."""
    s = 'safe <script>alert("omg")</script>'
    t = PurifiedTranslation(localized_string=s)
    actual = env.from_string('{{ s|truncate(100) }}').render({'s': t})
    eq_(actual, 'safe &lt;script&gt;alert("omg")&lt;/script&gt;')
    actual = env.from_string('{{ s|truncate(5) }}').render({'s': t})
    eq_(actual, 'safe ...')
Beispiel #7
0
 def test_newlines_ul(self):
     before = ("<ul>\n\n"
               "<li>No nl's between the ul and the li.</li>\n\n"
               "<li>No nl's between li's.\n\n"
               "But there should be two before this line.</li>\n\n"
               "</ul>")
     after = ("<ul>"
              "<li>No nl's between the ul and the li.</li>"
              "<li>No nl's between li's.\n\n"
              "But there should be two before this line.</li>"
              "</ul>")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #8
0
    def test_newlines_li_newlines(self):
        before = ("<ul><li>\nxx</li></ul>")
        after = ("<ul><li>xx</li></ul>")
        eq_(PurifiedTranslation(localized_string=before).__html__(), after)

        before = ("<ul><li>xx\n</li></ul>")
        after = ("<ul><li>xx</li></ul>")
        eq_(PurifiedTranslation(localized_string=before).__html__(), after)

        before = ("<ul><li>xx\nxx</li></ul>")
        after = ("<ul><li>xx\nxx</li></ul>")
        eq_(PurifiedTranslation(localized_string=before).__html__(), after)

        before = ("<ul><li></li></ul>")
        after = ("<ul><li></li></ul>")
        eq_(PurifiedTranslation(localized_string=before).__html__(), after)

        # All together now
        before = ("<ul><li>\nxx</li> <li>xx\n</li> <li>xx\nxx</li> "
                  "<li></li>\n</ul>")
        after = ("<ul><li>xx</li> <li>xx</li> <li>xx\nxx</li> "
                 "<li></li></ul>")
        eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #9
0
 def test_newlines_unclosed_b_wrapped(self):
     before = ("This is a <b>test")
     after = ("This is a <b>test</b>")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #10
0
 def test_newlines_attribute_nestedquotes_singledouble(self):
     before = '<abbr title=\'laugh "out" loud\'>lol</abbr>'
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #11
0
 def test_newlines_attribute_doublequote(self):
     before = '<abbr title="laugh out loud">lol</abbr>'
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #12
0
 def test_newlines_code_inline(self):
     before = ("Code tags aren't blocks.\n\n"
               "<code>alert(test);</code>\n\n"
               "See?")
     after = before  # Should stay the same
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #13
0
def test_truncate_purified_field():
    s = '<i>one</i><i>two</i>'
    t = PurifiedTranslation(localized_string=s)
    actual = env.from_string('{{ s|truncate(6) }}').render({'s': t})
    eq_(actual, s)
Beispiel #14
0
 def test_newlines_less_than(self):
     before = "3 < 5"
     after = "3 &lt; 5"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #15
0
 def test_newlines_malformed_tag(self):
     before = "<strong"
     after = ""
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #16
0
 def test_newlines_spaced_inline(self):
     before = "Line.\n\n<b>\nThis line is bold.\n</b>\n\nThis isn't."
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #17
0
 def test_newlines_spaced_blocks(self):
     before = ("<blockquote>\n\n<ul>\n\n<li>\n\ntest\n\n</li>\n\n"
               "</ul>\n\n</blockquote>")
     after = "<blockquote><ul><li>test</li></ul></blockquote>"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #18
0
 def test_newlines_li_all_inline(self):
     before = ("Test with <b>no newlines</b> and <code>block level "
               "stuff</code> to see what happens.")
     after = before  # Should stay the same
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #19
0
 def test_newlines_li_newlines_inline(self):
     before = ("<ul><li>\n<b>test\ntest\n\ntest</b>\n</li>"
               "<li>Test <b>test</b> test.</li></ul>")
     after = ("<ul><li><b>test\ntest\n\ntest</b></li>"
              "<li>Test <b>test</b> test.</li></ul>")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #20
0
 def test_newlines_empty_tag_block_nested_spaced(self):
     before = ("Test.\n\n<blockquote>\n\n<ul>\n\n<li>"
               "</li>\n\n</ul>\n\n</blockquote>\ntest.")
     after = ("Test.\n\n<blockquote><ul><li></li></ul></blockquote>test.")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #21
0
 def test_newlines_empty_tag_nested(self):
     before = ("This is a <b><i></i></b> test!")
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #22
0
 def test_newlines_unclosed_li(self):
     before = ("<ul><li>test</ul>")
     after = ("<ul><li>test</li></ul>")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #23
0
 def test_newlines_correct_faketag(self):
     before = "<madonna>"
     after = "&lt;madonna&gt;"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #24
0
 def test_newlines_xss_script(self):
     before = "<script>\n\nalert('test');\n</script>"
     after = "&lt;script&gt;\n\nalert('test');\n&lt;/script&gt;"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #25
0
 def test_newlines_malformed_tag_surrounded(self):
     before = "This is a <strong of bleach"
     after = "This is a"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #26
0
 def test_newlines_xss_inline(self):
     before = "<b onclick=\"alert('test');\">test</b>"
     after = "<b>test</b>"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #27
0
 def test_newlines_less_than_tight(self):
     before = "abc 3<5 def"
     after = "abc 3&lt;5 def"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #28
0
 def test_newlines_attribute_link_doublequote(self):
     before = '<a href="http://google.com">test</a>'
     after = '<a href="http://google.com">test</a>'
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #29
0
 def test_newlines_nested_inline(self):
     before = "<b>\nThis line is bold.\n\n<i>This is also italic</i></b>"
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Beispiel #30
0
 def test_newlines_inline(self):
     before = ("If we end a paragraph w/ a <b>non-block-level tag</b>\n\n"
               "<b>The newlines</b> should be kept")
     after = before  # Should stay the same
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)