Skip to content

Commit 3ca02f5

Browse files
authored
fix: disallow uppercase in package name (#527)
closes #523
1 parent c6153e2 commit 3ca02f5

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

.changes/package-name-uppercase.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-tauri-app": "patch"
3+
"create-tauri-app-js": "patch"
4+
---
5+
Disallow using an uppercase in the package name.
6+

packages/cli/src/lib.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -376,29 +376,18 @@ where
376376
}
377377

378378
fn is_valid_pkg_name(project_name: &str) -> bool {
379-
!project_name
380-
.chars()
381-
.next()
382-
.map(|c| c.is_ascii_digit())
383-
.unwrap_or_default()
384-
&& !project_name
385-
.chars()
386-
.any(|ch| !(ch.is_alphanumeric() || ch == '-' || ch == '_'))
387-
&& !project_name.is_empty()
379+
let mut chars = project_name.chars().peekable();
380+
!project_name.is_empty()
381+
&& !chars.peek().map(|c| c.is_ascii_digit()).unwrap_or_default()
382+
&& !chars.any(|ch| !(ch.is_alphanumeric() || ch == '-' || ch == '_') || ch.is_uppercase())
388383
}
389384

390385
fn to_valid_pkg_name(project_name: &str) -> String {
391-
#[allow(clippy::collapsible_str_replace)]
392386
let ret = project_name
393387
.trim()
394388
.to_lowercase()
395-
.replace(':', "-")
396-
.replace(';', "-")
397-
.replace(' ', "-")
398-
.replace('~', "-")
399-
.replace('.', "")
400-
.replace('\\', "")
401-
.replace('/', "");
389+
.replace([':', ';', ' ', '~'], "-")
390+
.replace(['.', '\\', '/'], "");
402391

403392
let ret = ret
404393
.chars()
@@ -427,6 +416,7 @@ mod test {
427416
assert!(!is_valid_pkg_name("tauri/app"));
428417
assert!(!is_valid_pkg_name("tauri\\app"));
429418
assert!(!is_valid_pkg_name("tauri~app"));
419+
assert!(!is_valid_pkg_name("Tauriapp"));
430420
}
431421

432422
#[test]
@@ -448,5 +438,6 @@ mod test {
448438
assert_eq!(to_valid_pkg_name("-123tauri.app"), "tauriapp");
449439
assert_eq!(to_valid_pkg_name("-2-123tau2ri-app-2"), "tau2ri-app-2");
450440
assert_eq!(to_valid_pkg_name("1-2-3tau2ri-app2-"), "tau2ri-app2-");
441+
assert_eq!(to_valid_pkg_name("Tauriapp"), "tauriapp");
451442
}
452443
}

0 commit comments

Comments
 (0)