@@ -143,7 +143,7 @@ impl RawScript {
143
143
// more common convention for CLIs
144
144
'-'
145
145
} ;
146
- let name = restricted_names :: sanitize_package_name ( & file_name, separator) ;
146
+ let name = sanitize_name ( & file_name, separator) ;
147
147
let hash = self . hash ( ) ;
148
148
let bin_name = format ! ( "{name}{separator}{hash}" ) ;
149
149
package
@@ -200,6 +200,29 @@ impl RawScript {
200
200
}
201
201
}
202
202
203
+ /// Ensure the package name matches the validation from `opt::cargo_new::check_name`
204
+ fn sanitize_name ( name : & str , placeholder : char ) -> String {
205
+ let mut name = restricted_names:: sanitize_package_name ( name, placeholder) ;
206
+
207
+ loop {
208
+ if restricted_names:: is_keyword ( & name) {
209
+ name. push ( placeholder) ;
210
+ } else if restricted_names:: is_conflicting_artifact_name ( & name) {
211
+ // Being an embedded manifest, we always assume it is a `[[bin]]`
212
+ name. push ( placeholder) ;
213
+ } else if name == "test" {
214
+ name. push ( placeholder) ;
215
+ } else if restricted_names:: is_windows_reserved ( & name) {
216
+ // Go ahead and be consistent across platforms
217
+ name. push ( placeholder) ;
218
+ } else {
219
+ break ;
220
+ }
221
+ }
222
+
223
+ name
224
+ }
225
+
203
226
fn default_target_dir ( ) -> CargoResult < std:: path:: PathBuf > {
204
227
let mut cargo_home = home:: cargo_home ( ) ?;
205
228
cargo_home. push ( "eval" ) ;
@@ -428,12 +451,12 @@ mod test_expand {
428
451
fn test_default ( ) {
429
452
snapbox:: assert_eq (
430
453
r#"[[bin]]
431
- name = "test-a472c7a31645d310613df407eab80844346938a3b8fe4f392cae059cb181aa85"
454
+ name = "test-- a472c7a31645d310613df407eab80844346938a3b8fe4f392cae059cb181aa85"
432
455
path = "/home/me/test.rs"
433
456
434
457
[package]
435
458
edition = "2021"
436
- name = "test"
459
+ name = "test- "
437
460
publish = false
438
461
version = "0.0.0"
439
462
@@ -450,15 +473,15 @@ strip = true
450
473
fn test_dependencies ( ) {
451
474
snapbox:: assert_eq (
452
475
r#"[[bin]]
453
- name = "test-3a1fa07700654ea2e893f70bb422efa7884eb1021ccacabc5466efe545da8a0b"
476
+ name = "test-- 3a1fa07700654ea2e893f70bb422efa7884eb1021ccacabc5466efe545da8a0b"
454
477
path = "/home/me/test.rs"
455
478
456
479
[dependencies]
457
480
time = "0.1.25"
458
481
459
482
[package]
460
483
edition = "2021"
461
- name = "test"
484
+ name = "test- "
462
485
publish = false
463
486
version = "0.0.0"
464
487
0 commit comments