Example #1
0
  def testSanitization(self):
    dangerous = "<script>alert('xss')</script>"
    sanitized = "&lt;script&gt;alert('xss')&lt;/script&gt;"
    self.assertEqual(text_plugin.markdown_and_sanitize(dangerous), sanitized)

    dangerous = textwrap.dedent("""\
    hello <a name='n'
    href='javascript:alert('xss')'>*you*</a>""")
    sanitized = '<p>hello <a><em>you</em></a></p>'
    self.assertEqual(text_plugin.markdown_and_sanitize(dangerous), sanitized)
Example #2
0
    def test_text_array_to_html(self):

        convert = text_plugin.text_array_to_html
        scalar = np.array('foo')
        scalar_expected = '<p>foo</p>'
        self.assertEqual(convert(scalar), scalar_expected)

        vector = np.array(['foo', 'bar'])
        vector_expected = textwrap.dedent("""\
      <table>
      <tbody>
      <tr>
      <td><p>foo</p></td>
      </tr>
      <tr>
      <td><p>bar</p></td>
      </tr>
      </tbody>
      </table>""")
        self.assertEqual(convert(vector), vector_expected)

        d2 = np.array([['foo', 'bar'], ['zoink', 'zod']])
        d2_expected = textwrap.dedent("""\
      <table>
      <tbody>
      <tr>
      <td><p>foo</p></td>
      <td><p>bar</p></td>
      </tr>
      <tr>
      <td><p>zoink</p></td>
      <td><p>zod</p></td>
      </tr>
      </tbody>
      </table>""")
        self.assertEqual(convert(d2), d2_expected)

        d3 = np.array([[['foo', 'bar'], ['zoink', 'zod']],
                       [['FOO', 'BAR'], ['ZOINK', 'ZOD']]])

        warning = text_plugin.markdown_and_sanitize(
            text_plugin.WARNING_TEMPLATE % 3)
        d3_expected = warning + textwrap.dedent("""\
      <table>
      <tbody>
      <tr>
      <td><p>foo</p></td>
      <td><p>bar</p></td>
      </tr>
      <tr>
      <td><p>zoink</p></td>
      <td><p>zod</p></td>
      </tr>
      </tbody>
      </table>""")
        self.assertEqual(convert(d3), d3_expected)
Example #3
0
 def assertConverted(self, actual, expected):
     expected_html = text_plugin.markdown_and_sanitize(expected)
     self.assertEqual(actual, expected_html)
Example #4
0
    def testMarkdownConversion(self):
        emphasis = '*Italics1* _Italics2_ **bold1** __bold2__'
        emphasis_converted = (
            '<p><em>Italics1</em> <em>Italics2</em> '
            '<strong>bold1</strong> <strong>bold2</strong></p>')

        self.assertEqual(text_plugin.markdown_and_sanitize(emphasis),
                         emphasis_converted)

        md_list = textwrap.dedent("""\
    1. List item one.
    2. List item two.
      * Sublist
      * Sublist2
    1. List continues.
    """)
        md_list_converted = textwrap.dedent("""\
    <ol>
    <li>List item one.</li>
    <li>List item two.</li>
    <li>Sublist</li>
    <li>Sublist2</li>
    <li>List continues.</li>
    </ol>""")
        self.assertEqual(text_plugin.markdown_and_sanitize(md_list),
                         md_list_converted)

        link = '[TensorFlow](http://tensorflow.org)'
        link_converted = '<p><a href="http://tensorflow.org">TensorFlow</a></p>'
        self.assertEqual(text_plugin.markdown_and_sanitize(link),
                         link_converted)

        table = textwrap.dedent("""\
    An | Example | Table
    --- | --- | ---
    A | B | C
    1 | 2 | 3
    """)

        table_converted = textwrap.dedent("""\
    <table>
    <thead>
    <tr>
    <th>An</th>
    <th>Example</th>
    <th>Table</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>A</td>
    <td>B</td>
    <td>C</td>
    </tr>
    <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    </tr>
    </tbody>
    </table>""")

        self.assertEqual(text_plugin.markdown_and_sanitize(table),
                         table_converted)
Example #5
0
 def assertTextConverted(self, actual, expected):
     self.assertEqual(text_plugin.markdown_and_sanitize(actual), expected)