Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(name: str = "World"):
"""
if len(name) > 100:
raise UsageError("Invalid name: maximum length is 100 characters.")
if any(c < " " for c in name):
if any(not c.isprintable() for c in name):
raise UsageError("Invalid name: control characters are not allowed.")

secho(f"Hello {name}! 👋", fg="green", bold=True)
Expand Down
2 changes: 1 addition & 1 deletion scripts/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main(name: str, description: str, author: str, email: str, github: str):
]:
if len(value) > 100:
raise UsageError(f"Invalid {label}: maximum length is 100 characters.")
if any(c < " " for c in value):
if any(not c.isprintable() for c in value):
raise UsageError(f"Invalid {label}: control characters are not allowed.")
if label != "description" and '"' in value:
raise UsageError(f"Invalid {label}: double quotes are not allowed.")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ def test_name_control_characters():
result = runner.invoke(main, ["--name", "Injected\x1b[31mRed\x1b[0m"])
assert result.exit_code != 0
assert "control characters are not allowed" in result.output

result = runner.invoke(main, ["--name", "test\x7f"])
assert result.exit_code != 0
assert "control characters are not allowed" in result.output