Fix the project name check in a CI script
Your task
Your CI backup script runs tar czf backup.tgz $PROJECT and then copies the archive to S3. $PROJECT comes from a branch or pull request field, so anyone who can open a pull request chooses it. The script refuses to run until the name passes a check.
An assistant wrote project_name_is_safe(name). It is in the editor. It has a bug. Find it and fix it.
Input and output:
name: the project name from the pipeline.- Return true when the script may use the name, false otherwise.
Rules the tests check. A name is safe only when all of these hold:
- It is 1 to 64 characters long.
- Every character is an ASCII letter, a digit from 0 to 9,
.,_or-. So no spaces, no*, no/and no newlines. - It does not start with
-.tarreads an argument that starts with-as an option, even when the script quotes it. - It is not
.or... Other names that start with a dot, like.hidden, are fine.
Examples
project_name_is_safe(name: str) -> boolExample 1
Input
project_name_is_safe("main")Output
TrueExample 2
Input
project_name_is_safe("--checkpoint-action=exec=sh -c id")Output
FalseExample 3
Input
project_name_is_safe("release_2026.01")Output
True