Skip to content

Commit

Permalink
fix: Append to preexisting MSYS env var even if ill-formed
Browse files Browse the repository at this point in the history
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 GitoxideLabs#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.
  • Loading branch information
EliahKagan committed Sep 6, 2024
1 parent fbd4908 commit 8dc5d7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ fn configure_command<'a>(
args: &[String],
script_result_directory: &Path,
) -> &'a mut std::process::Command {
let mut msys_for_git_bash_on_windows = std::env::var("MSYS").unwrap_or_default();
msys_for_git_bash_on_windows.push_str(" winsymlinks:nativestrict");
let mut msys_for_git_bash_on_windows = std::env::var_os("MSYS").unwrap_or_default();
msys_for_git_bash_on_windows.push(" winsymlinks:nativestrict");
cmd.args(args)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
Expand Down

0 comments on commit 8dc5d7a

Please sign in to comment.