Skip to content

Commit 8dc5d7a

Browse files
committed
fix: Append to preexisting MSYS env var even if ill-formed
The value of an environment variable as obtained by the facilities in `std::env` is not always well-formed Unicode. Specifically, on Windows the values of environment variables, like paths, are natively UTF-16LE strings except that unpaired surrogate code points can also occur. An `&OsStr` on Windows may accordingly not quite be UTF-8. When the `MSYS` variable is absent, we treat this the same as when it is present but empty. However, as described in #1574, an `MSYS` variable that is present but whose value contains an unpaired surrogate would also be replaced entirely, rather than appending to its old value. This changes that, to instead append, retaining whatever was there even if it was ill-formed Unicode. An alternative change could be to panic when the old value is ill-formed Unicode. This commit allows and appends to the old value, rather than panicking or keeping and documenting the previous behavior of discarding the old value, because the appended sequence ` winsymlinks:nativestrict` is effective at causing fixture scripts to attempt to create actual symlinks even if the preceding code point is an unpaired Unicode high surrogate.
1 parent fbd4908 commit 8dc5d7a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/tools/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ fn configure_command<'a>(
593593
args: &[String],
594594
script_result_directory: &Path,
595595
) -> &'a mut std::process::Command {
596-
let mut msys_for_git_bash_on_windows = std::env::var("MSYS").unwrap_or_default();
597-
msys_for_git_bash_on_windows.push_str(" winsymlinks:nativestrict");
596+
let mut msys_for_git_bash_on_windows = std::env::var_os("MSYS").unwrap_or_default();
597+
msys_for_git_bash_on_windows.push(" winsymlinks:nativestrict");
598598
cmd.args(args)
599599
.stdout(std::process::Stdio::piped())
600600
.stderr(std::process::Stdio::piped())

0 commit comments

Comments
 (0)