From e7b4c0d4dd1c867d94ee1eeb7821251ef81808b2 Mon Sep 17 00:00:00 2001 From: cmccabe Date: Sun, 8 Dec 2019 11:40:25 +0000 Subject: [PATCH] validation of user input in replies --- linkulator | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/linkulator b/linkulator index 8a14292..6fc333d 100755 --- a/linkulator +++ b/linkulator @@ -252,22 +252,28 @@ def reply(owner, tstamp, post_id): comment = input("Enter your comment (or leave empty to abort): ") - if comment == "": - input("Reply aborted. Hit [Enter] to continue.") - else: - if os.path.exists(config.USER.datafile): - append_write = "a" # append if already exists + while True: + if comment == "": + input("Reply aborted. Hit [Enter] to continue.") + break + elif not posts.is_valid(comment): + print("Please try again, that response contains invalid characters.") + comment = posts.rlinput("Enter your comment (or leave empty to abort):") else: - append_write = "w+" # make a new file if not - with open(config.USER.datafile, append_write) as file: - timestamp = str(time.time()) - file.write(timestamp + "|" + owner + "+" + tstamp + "|||" + comment + "\n") + if os.path.exists(config.USER.datafile): + append_write = "a" # append if already exists + else: + append_write = "w+" # make a new file if not + with open(config.USER.datafile, append_write) as file: + timestamp = str(time.time()) + file.write(timestamp + "|" + owner + "+" + tstamp + "|||" + comment + "\n") - link_data.insert( - 0, ["", username, timestamp, owner + "+" + tstamp, "", "", comment] - ) + link_data.insert( + 0, ["", username, timestamp, owner + "+" + tstamp, "", "", comment] + ) - input("Reply added. Hit [Enter] to return to thread.") + input("Reply added. Hit [Enter] to return to thread.") + break view_thread(post_id)