Skip to content

Commit b6a7f98

Browse files
authored
Merge pull request #6 from rust-osdev/escape-spaces-in-rustflags
Escape spaces in rustflags
2 parents 9716bbc + 46cf0e0 commit b6a7f98

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Rustflags {
4545
pub fn for_xargo(&self, home: &Home) -> String {
4646
let mut flags = self.flags.clone();
4747
flags.push("--sysroot".to_owned());
48-
flags.push(home.display().to_string());
48+
flags.push(util::escape_argument_spaces(format!("{}", home.display())));
4949
flags.join(" ")
5050
}
5151
}

src/util.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,24 @@ pub fn write(path: &Path, contents: &str) -> Result<()> {
100100
.write_all(contents.as_bytes())
101101
.chain_err(|| format!("couldn't write to {}", p))
102102
}
103+
104+
/// Escapes spaces (` `) in the given input with `%20` or does nothing. Then
105+
/// it returns the processed string.
106+
/// ### Windows Only
107+
/// Doesn't do anything on non-windows systems because escaped output
108+
/// (containing `\ `) is still treated as two arguments because of the
109+
/// remaining space character.
110+
pub fn escape_argument_spaces<S: Into<String>>(arg: S) -> String {
111+
#[cfg(target_os = "windows")]
112+
let escaped = arg.into().replace(" ", "%20");
113+
114+
#[cfg(not(target_os = "windows"))]
115+
let escaped = arg.into();
116+
// Doesn't work because there's still a space character in the string
117+
// and it's still interpreted as a separation between two arguments.
118+
/*
119+
let escaped = arg.into().replace(" ", "\\ ");
120+
*/
121+
122+
escaped
123+
}

0 commit comments

Comments
 (0)