[odrs-web] Do some more content filtering serverside
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [odrs-web] Do some more content filtering serverside
- Date: Fri, 2 Jun 2017 20:04:04 +0000 (UTC)
commit d2d4cbe6611347f1bf8ea54800d9e09695565ca1
Author: Richard Hughes <richard hughsie com>
Date: Mon Apr 3 11:23:10 2017 +0100
Do some more content filtering serverside
api10.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/api10.py b/api10.py
index 8635799..0ab9f01 100644
--- a/api10.py
+++ b/api10.py
@@ -75,6 +75,44 @@ def _get_review_score(review, item):
wilson *= 100
return int(wilson)
+def _sanitised_input(val):
+
+ # remove trailing whitespace
+ val = val.strip()
+
+ # fix up style issues
+ val = val.replace('!!!', '!')
+ val = val.replace(':)', '')
+ val = val.replace(' ', ' ')
+
+ return val
+
+def _sanitised_summary(val):
+ val = _sanitised_input(val);
+ if val.endswith('.'):
+ val = val[:len(val)-1]
+ return val;
+
+def _sanitised_description(val):
+ return _sanitised_input(val);
+
+def _sanitised_version(val):
+
+ # remove epoch
+ idx = val.find(':')
+ if idx != -1:
+ val = val[idx+1:]
+
+ # remove distro addition
+ idx = val.find('+')
+ if idx != -1:
+ val = val[:idx]
+ idx = val.find('~')
+ if idx != -1:
+ val = val[:idx]
+
+ return val
+
@api.errorhandler(400)
def json_error(msg=None, errcode=400):
""" Error handler: JSON output """
@@ -163,8 +201,8 @@ def submit():
review = OdrsReview()
review.app_id = item['app_id']
review.locale = item['locale']
- review.summary = _sanitised_input(item['summary'])
- review.description = _sanitised_input(item['description'])
+ review.summary = _sanitised_summary(item['summary'])
+ review.description = _sanitised_description(item['description'])
review.user_hash = item['user_hash']
review.version = _sanitised_version(item['version'])
review.distro = item['distro']
@@ -511,3 +549,10 @@ def ratings():
return Response(response=dat,
status=200, \
mimetype="application/json")
+
+if __name__ == '__main__':
+ print ">>>%s<<<" % _sanitised_version("16.12.3")
+ print ">>>%s<<<" % _sanitised_version("4:16.12.3+p16.04+git20170325.0519-0")
+ print ">>>%s<<<" % _sanitised_version("16.11.0~ds0")
+ print ">>>%s<<<" % _sanitised_summary(" not sure why people include. ")
+ print ">>>%s<<<" % _sanitised_description(" this is awesome :) !!! ")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]