Skip to content

Commit 92910c0

Browse files
committed
util: Forbid control characters in input prompts
Signed-off-by: Hector Martin <[email protected]>
1 parent 6a450f2 commit 92910c0

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ def p_choice(*args):
110110
p_style(*args)
111111

112112
def input_prompt(*args):
113-
p_style(f"{col(BRIGHT, WHITE)}»{col(BRIGHT, CYAN)}", *args, end="")
114-
val = input()
113+
while True:
114+
p_style(f"{col(BRIGHT, WHITE)}»{col(BRIGHT, CYAN)}", *args, end="")
115+
val = input()
116+
if any (ord(c) < 0x20 for c in val):
117+
p_error("Invalid input")
118+
continue
119+
break
115120
logging.info(f"INPUT: {val!r}")
116121
return val
117122

0 commit comments

Comments
 (0)