From 60709a72537cef5821631b7eec8fb43d7f6f4b0e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 31 Aug 2022 03:48:20 +0200 Subject: [PATCH] add error handling for incorrect time format in search --- files/routes/search.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/files/routes/search.py b/files/routes/search.py index 213f1a009..09d50d7a6 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -137,13 +137,17 @@ def searchposts(v): if 'after' in criteria: after = criteria['after'] try: after = int(after) - except: after = timegm(time.strptime(after, "%Y-%m-%d")) + except: + try: after = timegm(time.strptime(after, "%Y-%m-%d")) + except: abort(400) posts = posts.filter(Submission.created_utc > after) if 'before' in criteria: before = criteria['before'] try: before = int(before) - except: before = timegm(time.strptime(before, "%Y-%m-%d")) + except: + try: before = timegm(time.strptime(before, "%Y-%m-%d")) + except: abort(400) posts = posts.filter(Submission.created_utc < before) posts = apply_time_filter(t, posts, Submission) @@ -243,13 +247,17 @@ def searchcomments(v): if 'after' in criteria: after = criteria['after'] try: after = int(after) - except: after = timegm(time.strptime(after, "%Y-%m-%d")) + except: + try: after = timegm(time.strptime(after, "%Y-%m-%d")) + except: abort(400) comments = comments.filter(Comment.created_utc > after) if 'before' in criteria: before = criteria['before'] try: before = int(before) - except: before = timegm(time.strptime(before, "%Y-%m-%d")) + except: + try: before = timegm(time.strptime(before, "%Y-%m-%d")) + except: abort(400) comments = comments.filter(Comment.created_utc < before) comments = sort_comments(sort, comments)