Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit bbd6531

Browse files
committed
updating the contracts GET endpoint to use the utlitity sanitize_html function
1 parent 9fd897d commit bbd6531

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

api/restapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from market.btcprice import BtcPrice
2929
from net.upnp import PortMapper
3030
from api import ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES
31+
from utils import sanitize_html
3132

3233
DEFAULT_RECORDS_COUNT = 20
3334
DEFAULT_RECORDS_OFFSET = 0
@@ -494,7 +495,7 @@ def get_contract(self, request):
494495
def parse_contract(contract):
495496
if contract is not None:
496497
request.setHeader('content-type', "application/json")
497-
request.write(bleach.clean(json.dumps(contract, indent=4), tags=ALLOWED_TAGS).encode("utf-8"))
498+
request.write(json.dumps(sanitize_html(contract), indent=4))
498499
request.finish()
499500
else:
500501
request.write(json.dumps({}))

api/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import bleach
22

3+
from api import ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES
4+
35
# pylint: disable=W1402
46
def smart_unicode(s, encoding='utf8'):
57
""" Convert str to unicode. If s is unicode, return itself.
@@ -43,5 +45,5 @@ def sanitize_html(value):
4345
elif isinstance(value, list):
4446
value = [sanitize_html(v) for v in value]
4547
elif isinstance(value, basestring):
46-
value = bleach.clean(value)
48+
value = bleach.clean(value, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES, styles=ALLOWED_STYLES)
4749
return value

0 commit comments

Comments
 (0)