@@ -21,8 +21,10 @@ def main(name: str, description: str, author: str, email: str, github: str):
2121 ("email" , email ),
2222 ("github" , github ),
2323 ]:
24- if "\n " in value or "\r " in value :
25- raise UsageError (f"Invalid { label } : newlines are not allowed." )
24+ if len (value ) > 100 :
25+ raise UsageError (f"Invalid { label } : maximum length is 100 characters." )
26+ if any (c < " " for c in value ):
27+ raise UsageError (f"Invalid { label } : control characters are not allowed." )
2628 if label != "description" and '"' in value :
2729 raise UsageError (f"Invalid { label } : double quotes are not allowed." )
2830
@@ -31,8 +33,19 @@ def main(name: str, description: str, author: str, email: str, github: str):
3133 f"Invalid project name '{ name } '. Only alphanumeric characters, dashes, and underscores are allowed."
3234 )
3335
34- # Sanitize description for TOML double-quoted strings
35- description = description .replace ('"' , '\\ "' )
36+ if not re .match (r"^[a-zA-Z0-9-]+$" , github ):
37+ raise UsageError (f"Invalid GitHub username '{ github } '. Only alphanumeric characters and dashes are allowed." )
38+
39+ if not re .match (r"^[^@]+@[^@]+\.[^@]+$" , email ):
40+ raise UsageError (f"Invalid email address '{ email } '." )
41+
42+ # Sanitize for TOML double-quoted strings (escape backslashes and double quotes)
43+ def toml_escape (s : str ) -> str :
44+ return s .replace ("\\ " , "\\ \\ " ).replace ('"' , '\\ "' )
45+
46+ description = toml_escape (description )
47+ author = toml_escape (author )
48+ email = toml_escape (email )
3649
3750 source = name .replace ("-" , "_" ).lower ()
3851
0 commit comments