コード例 #1
0
def escape(text):
    if text is None:
        text = ''
    try:
        if _is_string_html(text):
            text = sanitize_for_platypus(text)
        else:
            text = cgi.escape(text)
            text = text.replace('\r\n', ' <br/>')
            text = text.replace('\n', ' <br/>')
            text = text.replace('\r', ' <br/>')
        return text
    except Exception:
        return saxutils.escape(text)
コード例 #2
0
ファイル: base.py プロジェクト: nyimbi/indico
def escape(text):
    if text is None:
        text = ""
    try:
        if isStringHTML(text):
            text = sanitize_for_platypus(text)
        else:
            text = cgi.escape(text)
            text = text.replace("\r\n", " <br/>")
            text = text.replace("\n", " <br/>")
            text = text.replace("\r", " <br/>")
        return text
    except Exception:
        return saxutils.escape(text)
コード例 #3
0
ファイル: string_test.py プロジェクト: javfg/indico
def test_sanitize_for_platypus_relative_urls():
    html = textwrap.dedent('''
        <p>
            <img src="https://example.com/test.png"/>
            <img src="//example.com/test.png"/>
            <img src="/test.png"/>
        </p>
    ''').strip()
    expected = textwrap.dedent('''
        <p>
            <img src="https://example.com/test.png"/>
            <img src="http://example.com/test.png"/>
            <img src="http://localhost/test.png"/>
        </p>
    ''').strip()
    assert sanitize_for_platypus(html) == expected