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)
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)
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