Skip to content

Commit

Permalink
fix invalid char
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 28, 2024
1 parent cbf436a commit 19536bf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
"Cf",
}

__white_space_char = {"\t", "\r", "\n"}


def check_invalid_input_str(*ss: str) -> None:
for s in ss:
for c in s:
if c == "\t":
if c in __white_space_char:
continue

v = unicodedata.category(c)
if v in _invalid_category:
raise BadRequestException("invalid character {!r}".format(c))
Expand All @@ -24,6 +27,10 @@ def invisible_escape(s: str) -> str:
with io.StringIO() as f:
for ss in s:
for c in ss:
if c in __white_space_char:
f.write(c)
continue

v = unicodedata.category(c)
if v in _invalid_category:
f.write(c.encode("unicode-escape").decode())
Expand Down

0 comments on commit 19536bf

Please sign in to comment.