Example #1
0
 def test_table(self):
     """
     Tests that tables are correctly bleached
     """
     text = u'Table: <table><tr><th>col</th><td>data</td></tr></table>'
     expected = u'Table: <table><tbody><tr><th>col</th><td>data</td></tr></tbody></table>'
     self.assertEqual(expected, bleach_clean(text))
Example #2
0
 def test_line_breaks(self):
     """
     Tests that tables are correctly bleached
     """
     text = u'Line breaks: <br> </br> <br/> <br />'
     expected = u'Line breaks: <br/> <br/> <br/> <br/>'
     self.assertEqual(expected, bleach_clean(text))
Example #3
0
 def test_line_breaks(self):
     """
     Tests that tables are correctly bleached
     """
     text = u'Line breaks: <br> </br> <br/> <br />'
     expected = u'Line breaks: <br/> <br/> <br/> <br/>'
     self.assertEqual(expected, bleach_clean(text))
Example #4
0
 def test_table(self):
     """
     Tests that tables are correctly bleached
     """
     text = u'Table: <table><tr><th>col</th><td>data</td></tr></table>'
     expected = u'Table: <table><tbody><tr><th>col</th><td>data</td></tr></tbody></table>'
     self.assertEqual(expected, bleach_clean(text))
Example #5
0
 def test_bad_html(self):
     """
     Tests not allowed html is bleached
     """
     texts = [
         (u'Script: <script>nasty java script...', u'Script: &lt;script&gt;nasty java script...', )
     ]
     for text, expected in texts:
         self.assertEqual(expected, bleach_clean(text))
Example #6
0
 def test_bad_html(self):
     """
     Tests not allowed html is bleached
     """
     texts = [(
         u'Script: <script>nasty java script...',
         u'Script: &lt;script&gt;nasty java script...',
     )]
     for text, expected in texts:
         self.assertEqual(expected, bleach_clean(text))
Example #7
0
 def test_white_listed(self):
     """
     Tests that white listed html tags are not removed by bleach
     """
     texts = [
         u'Superscript: <sup>italics</sup>',
         u'Subscript: <sub>italics</sub>',
         u'Links: <a href="http://www.uanwe.org/" target="_blank">UNAWE</a>',
         u'Italics: <em>italics</em>',
         u'Paragraph: <p>italics</p>',
     ]
     for text in texts:
         self.assertEqual(text, bleach_clean(text))
Example #8
0
 def test_white_listed(self):
     """
     Tests that white listed html tags are not removed by bleach
     """
     texts = [
         u'Superscript: <sup>italics</sup>',
         u'Subscript: <sub>italics</sub>',
         u'Links: <a href="http://www.uanwe.org/" target="_blank">UNAWE</a>',
         u'Italics: <em>italics</em>',
         u'Paragraph: <p>italics</p>',
     ]
     for text in texts:
         self.assertEqual(text, bleach_clean(text))
Example #9
0
    def clean(self):
        cleaned_data = super().clean()

        age = cleaned_data.get('age')
        level = cleaned_data.get('level')
        if not age and not level:
            raise forms.ValidationError('Please fill in at least one of these fields: "Age", "Level"')

        for fieldname in ('description', 'materials', 'goals', 'objectives', 'background', 'fulldesc', 'evaluation', 'curriculum', 'additional_information', 'conclusion', ):
            value = cleaned_data.get(fieldname)
            value = bleach_clean(value)  # sanitize html embed in markdown
            cleaned_data[fieldname] = value
            try:
                markdown(value)
            except:
                # TODO: test error logging!
                import sys
                e = sys.exc_info()[0]
                print(e)
                self.add_error(fieldname, _('Markdown error'))

        return cleaned_data