diff --git a/project/app.py b/project/app.py index 69b87be..e385b11 100644 --- a/project/app.py +++ b/project/app.py @@ -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) diff --git a/scripts/rename.py b/scripts/rename.py index a0dfe46..c3d56a7 100644 --- a/scripts/rename.py +++ b/scripts/rename.py @@ -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.") diff --git a/tests/test_app.py b/tests/test_app.py index ef2df6c..7c414cd 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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