From 25d1be3791e0949004cd6745457db9d21714d2cf Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 19 Sep 2021 11:31:14 +1000 Subject: [PATCH] thrimshim: Further validation of titles/descriptions Youtube doesn't allow < or > characters, or extremely long descriptions. Fixes #215, #219 --- thrimshim/thrimshim/main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/thrimshim/thrimshim/main.py b/thrimshim/thrimshim/main.py index 93486bc..d32f847 100644 --- a/thrimshim/thrimshim/main.py +++ b/thrimshim/thrimshim/main.py @@ -28,6 +28,7 @@ app.after_request(after_request) MAX_TITLE_LENGTH = 100 # Youtube only allows 100-character titles +MAX_DESCRIPTION_LENGTH = 5000 # Youtube only allows 5000-character descriptions def cors(app): @@ -228,9 +229,16 @@ def update_row(ident, editor=None): if 'video_description' in new_row: new_row['video_description'] += app.description_footer - # Validate title length + # Validate youtube requirements on title and description if len(new_row['video_title']) > MAX_TITLE_LENGTH: return 'Title must be {} characters or less, including prefix'.format(MAX_TITLE_LENGTH), 400 + if len(new_row['video_description']) > MAX_DESCRIPTION_LENGTH: + return 'Description must be {} characters or less, including footer'.format(MAX_DESCRIPTION_LENGTH), 400 + for char in ['<', '>']: + if char in new_row['video_title']: + return 'Title may not contain a {} character'.format(char), 400 + if char in new_row['video_description']: + return 'Description may not contain a {} character'.format(char), 400 # Validate start time is less than end time if new_row['video_start'] > new_row['video_end']: return 'Video Start must be less than Video End.', 400