Fix the project name check in a CI script

Review the AI's codeEasy10 min

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 -. tar reads 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) -> bool
Example 1
Inputproject_name_is_safe("main")
OutputTrue
Example 2
Inputproject_name_is_safe("--checkpoint-action=exec=sh -c id")
OutputFalse
Example 3
Inputproject_name_is_safe("release_2026.01")
OutputTrue