Skip to content

Commit

Permalink
Fix #145
Browse files Browse the repository at this point in the history
  • Loading branch information
twd2 committed May 1, 2017
1 parent 4fa65e7 commit 3a5e1ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions vj4/model/adaptor/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ async def get(domain_id: str, did: document.convert_doc_id):


async def edit(domain_id: str, did: document.convert_doc_id, **kwargs):
if 'title' in kwargs:
validator.check_title(kwargs['title'])
if 'content' in kwargs:
validator.check_content(kwargs['content'])
return await document.set(domain_id, document.TYPE_DISCUSSION, did, **kwargs)


Expand Down
6 changes: 3 additions & 3 deletions vj4/util/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def check_role(s):


def is_title(s):
return bool(re.fullmatch(r'.{1,64}', s))
return bool(re.fullmatch(r'.{1,64}', s.strip()))

This comment has been minimized.

Copy link
@iceboy233

iceboy233 May 1, 2017

Member

this is bad programming - you created a new string just for validation!



def check_title(s):
Expand All @@ -91,7 +91,7 @@ def check_name(s):


def is_content(s):
return isinstance(s, str) and len(str(s)) >= 2 and len(str(s)) <= 65536
return isinstance(s, str) and len(s.strip()) >= 2 and len(s.strip()) <= 65536


def check_content(s):
Expand All @@ -100,7 +100,7 @@ def check_content(s):


def is_description(s):
return isinstance(s, str) and len(str(s)) >= 1 and len(str(s)) <= 65536
return isinstance(s, str) and len(s.strip()) >= 1 and len(s.strip()) <= 65536


def check_description(s):
Expand Down

0 comments on commit 3a5e1ba

Please sign in to comment.