escape_html bulletproofing

pull/81/head
Chris Caron 2019-03-10 12:24:57 -04:00
parent 268d11f181
commit 741d244c5a
2 changed files with 8 additions and 3 deletions

View File

@ -24,6 +24,7 @@
# THE SOFTWARE. # THE SOFTWARE.
import re import re
import six
import logging import logging
from time import sleep from time import sleep
from datetime import datetime from datetime import datetime
@ -199,9 +200,8 @@ class URLBase(object):
Returns: Returns:
str: The escaped html str: The escaped html
""" """
if not html: if not isinstance(html, six.string_types) or not html:
# nothing more to do; return object as is return ''
return html
# Escape HTML # Escape HTML
escaped = sax_escape(html, {"'": "'", "\"": """}) escaped = sax_escape(html, {"'": "'", "\"": """})

View File

@ -196,6 +196,11 @@ def test_notify_base():
'/path/?name=Dr%20Disrespect', unquote=True) == \ '/path/?name=Dr%20Disrespect', unquote=True) == \
['path', '?name=Dr', 'Disrespect'] ['path', '?name=Dr', 'Disrespect']
# Give nothing, get nothing
assert NotifyBase.escape_html("") == ""
assert NotifyBase.escape_html(None) == ""
assert NotifyBase.escape_html(object()) == ""
# Test quote # Test quote
assert NotifyBase.unquote('%20') == ' ' assert NotifyBase.unquote('%20') == ' '
assert NotifyBase.quote(' ') == '%20' assert NotifyBase.quote(' ') == '%20'