Пример #1
0
    def test_autolink_filtering_with_nice_data(self):
        for url in ('http://a', "https://b?x&y"):
            actual = render('<%s>' % url)
            expected = '<p><a href="{0}">{0}</a></p>\n'.format(escape_html(url))
            ok(actual).diff(expected)

        supplied = "<*****@*****.**>"
        expected = '<p>%s</p>\n' % escape_html(supplied)
        ok(render_escape(supplied)).diff(expected)
Пример #2
0
    def test_autolink_rewriting(self):
        for url in ('http://a', 'https://b?x&y'):
            actual = render_rewrite('<%s>' % url)
            expected = '<p><a href="%s">%s</a></p>\n'
            expected %= (rewrite_url(url), escape_html(url))
            ok(actual).diff(expected)

        supplied = "<*****@*****.**>"
        expected = '<p>%s</p>\n' % escape_html(supplied)
        ok(render_escape(supplied)).diff(expected)
Пример #3
0
    def test_html_escape(self):
        supplied = 'Example <script>alert(1);</script>'
        expected = '<p>%s</p>\n' % escape_html(supplied)
        ok(render_escape(supplied)).diff(expected)

        html = render_escape('<sc<script>ript>xss</sc</script>ript>')
        ok(html).not_contains('<sc')
        ok(html).not_contains('ript>')

        supplied = '<span><a href="javascript:xss">foo</a></span>'
        expected = '<p>%s</p>\n' % escape_html(supplied)
        ok(render_escape(supplied)).diff(expected)
Пример #4
0
    def test_link_filtering_with_naughty_data(self):
        supplied = '[foo](javascript:xss)'
        expected = '<p>%s</p>\n' % escape_html(supplied)
        ok(render(supplied)).diff(expected)

        html = render('[foo](unknown:bar)')
        expected = '<p>%s</p>\n' % escape_html(supplied)
        ok(render(supplied)).diff(expected)

        html = render('[" xss><xss>]("><xss>)')
        ok(html).not_contains('<xss>')
        ok(html).not_contains('" xss')
        html = render('[" xss><xss>](https:"><xss>)')
        ok(html).not_contains('<xss>')
        ok(html).not_contains('" xss')
Пример #5
0
    def blockcode(self, text, lang):
        try:
            lexer = get_lexer_by_name(lang)
        except ClassNotFound:
            lexer = None

        if lexer:
            return highlight(text, lexer, html_formatter)

        return "\n<pre><code>{}</code></pre>\n".format(
            misaka.escape_html(text.strip()))
Пример #6
0
    def blockcode(self, text, lang):
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ClassNotFound:
            lexer = None

        if lexer:
            formatter = HtmlFormatter()
            return highlight(text, lexer, formatter)

        return '\n<pre><code>{}</code></pre>\n'.format(
            m.escape_html(text.strip()))
Пример #7
0
    def blockcode(text, lang):
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ClassNotFound:
            lexer = None

        if lexer:
            formatter = HtmlFormatter(cssclass='hi')
            return highlight(text, lexer, formatter)

        code = escape_html(text.strip())
        return f'<pre><code>{code}</code></pre>\n'
Пример #8
0
 def raw_html(self, context):
     return misaka.escape_html(context['text'])
Пример #9
0
 def blockcode(self, context):
     text = misaka.escape_html(context['text'])
     return '\n<pre><code>{}</pre></code>'.format(text)
Пример #10
0
 def save(self, *args, **kwargs):
     self.message_html = misaka.escape_html(self.message)
     super().save(*args, **kwargs)
Пример #11
0
 def test_escape_html(self):
     ok(escape_html('a&<>"\'/')) == 'a&amp;&lt;&gt;&quot;&#39;/'
Пример #12
0
 def test_escape_html_slash(self):
     ok(escape_html('a&<>"\'/', True)) == 'a&amp;&lt;&gt;&quot;&#39;&#47;'
Пример #13
0
 def link(self, content, url, title=''):
     maybe_title = ' title="%s"' % escape_html(title) if title else ''
     url = escape_html(url)
     return f'<a href="{escape_html(url)}" target="_blank"{maybe_title}>{content}</a>'