Added stricter rules to is_valid_project_name ##projects (#18598)

* Only allow lowercase letters, numbers and lowerdash
This commit is contained in:
RHL120 2021-04-19 14:15:27 +02:00 committed by GitHub
parent 88c76bc0f1
commit 13bc241a03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 19 deletions

View File

@ -12,23 +12,13 @@
// project apis to be used from cmd_project.c
static bool is_valid_project_name(const char *name) {
int i;
if (r_str_endswith (name, ".zip")) {
if (r_str_len_utf8 (name) >= 16) {
return false;
}
for (i = 0; name[i]; i++) {
switch (name[i]) {
case '\\': // for w32
case '.':
case '_':
case ':':
case '-':
continue;
}
if (isalpha ((unsigned char)name[i])) {
continue;
}
if (IS_DIGIT (name[i])) {
const char *extention = r_str_endswith (name, ".zip") ?
r_str_last (name, ".zip") : NULL;
for (; *name && name != extention; name++) {
if (IS_DIGIT (*name) || IS_LOWER (*name) || *name == '_') {
continue;
}
return false;

View File

@ -480,14 +480,14 @@ FILE=malloc://512
CMDS=<<EOF
e prj.git=false
e dir.projects = .tmp/
Ps named_prj > /dev/null
Ps namedprj > /dev/null
e prj.name=
Po named_prj > /dev/null
Po namedprj > /dev/null
e prj.name
rm .tmp/named_prj
rm .tmp/namedprj
EOF
EXPECT=<<EOF
named_prj
namedprj
EOF
RUN