Skip to content

Commit ad26525

Browse files
authored
Fix publishing in directories with spaces (#4453)
# Description of Changes The publish subcommand calls the build subcommand internally. The build's implementation used to split the arguments by space, which breaks when a directory contains a space. # API and ABI breaking changes - # Expected complexity level and risk 1 # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [x] Tested locally - [x] Added a test
1 parent 4375cb8 commit ad26525

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

crates/cli/src/subcommands/build.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ pub async fn exec_with_argstring(
9595
project_path: &Path,
9696
arg_string: &str,
9797
) -> Result<(PathBuf, &'static str), anyhow::Error> {
98-
// Note: "build" must be the start of the string, because `build::cli()` is the entire build subcommand.
99-
// If we don't include this, the args will be misinterpreted (e.g. as commands).
100-
let arg_string = format!("build {} --module-path {}", arg_string, project_path.display());
101-
let arg_matches = cli().get_matches_from(arg_string.split_whitespace());
98+
let argv = exec_with_argstring_argv(project_path, arg_string);
99+
let arg_matches = cli().get_matches_from(argv);
102100

103101
let module_path = arg_matches
104102
.get_one::<PathBuf>("module_path")
@@ -115,3 +113,35 @@ pub async fn exec_with_argstring(
115113

116114
run_build(module_path, lint_dir, build_debug, features)
117115
}
116+
117+
fn exec_with_argstring_argv(project_path: &Path, arg_string: &str) -> Vec<OsString> {
118+
// Note: "build" must be the first argv token because `build::cli()` is the entire build subcommand.
119+
// Keep module-path as its own argv item so paths containing spaces are not split.
120+
let mut argv: Vec<OsString> = vec!["build".into()];
121+
argv.extend(arg_string.split_whitespace().map(OsString::from));
122+
argv.push("--module-path".into());
123+
argv.push(project_path.as_os_str().to_os_string());
124+
argv
125+
}
126+
127+
#[cfg(test)]
128+
mod tests {
129+
use super::exec_with_argstring_argv;
130+
use std::path::Path;
131+
132+
#[test]
133+
fn exec_with_argstring_keeps_module_path_with_spaces_as_single_argv_item() {
134+
let project_path = Path::new("SpacetimeDB Projects/My SpacetimeDB App/spacetimedb");
135+
let argv = exec_with_argstring_argv(project_path, "--debug --lint-dir src");
136+
137+
assert_eq!(argv[0].to_string_lossy(), "build");
138+
assert_eq!(argv[1].to_string_lossy(), "--debug");
139+
assert_eq!(argv[2].to_string_lossy(), "--lint-dir");
140+
assert_eq!(argv[3].to_string_lossy(), "src");
141+
assert_eq!(argv[4].to_string_lossy(), "--module-path");
142+
assert_eq!(
143+
argv[5].to_string_lossy(),
144+
"SpacetimeDB Projects/My SpacetimeDB App/spacetimedb"
145+
);
146+
}
147+
}

0 commit comments

Comments
 (0)