Skip to content

Commit 0d01c30

Browse files
committed
Auto merge of #998 - RalfJung:comment, r=RalfJung
explain our shell encoding Follow-up to #980
2 parents 42c1e77 + 4ba63fb commit 0d01c30

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/bin/cargo-miri.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ path = "lib.rs"
340340
let sysroot = if is_host { dir.join("HOST") } else { PathBuf::from(dir) };
341341
std::env::set_var("MIRI_SYSROOT", &sysroot); // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags
342342
if print_env {
343+
// Escape an arbitrary string for the shell: by wrapping it in `'`, the only special
344+
// character we have to worry about is `'` itself. Everything else is taken literally
345+
// in these strings. `'` is encoded as `'"'"'`: the outer `'` end and being a
346+
// `'`-quoted string, respectively; the `"'"` in the middle represents a single `'`.
347+
// (We could use `'\''` instead of `'"'"'` if we wanted but let's avoid backslashes.)
343348
println!("MIRI_SYSROOT='{}'", sysroot.display().to_string().replace('\'', r#"'"'"'"#));
344349
} else if !ask_user {
345350
println!("A libstd for Miri is now available in `{}`.", sysroot.display());

0 commit comments

Comments
 (0)