Skip to content

Commit c9b0abe

Browse files
committed
Have it env use quoted/debug form when newlines are present
In addition to any invalid Unicode and double quotes, as before. + Revise its documentation.
1 parent 809fb2f commit c9b0abe

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

tests/it/src/args.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,15 @@ pub enum Subcommands {
7878
/// It is useful to be able to observe environment variables that are set when running code
7979
/// with tools such as `cargo` or `cross`. Commands like `cargo run -p internal-tools -- env`
8080
/// include environment changes from `cargo` itself. With `cross`, changes are more extensive,
81-
/// due to the effect of `build.env.passthrough`, container customization, and existing special
81+
/// due to effects of `build.env.passthrough`, container customization, and preexisting special
8282
/// cases in wrapper scripts shipped in default `cross` containers (such as to `LD_PRELOAD`).
8383
///
8484
/// Since one use for checking environment variables is to investigate the effects of
8585
/// environments that contain variable names or values that are not valid Unicode, this avoids
8686
/// requiring that environment variables all be Unicode. Any name or value that is not Unicode
87-
/// is shown in its Rust debug representation. This is always quoted, and to decrease ambiguity
88-
/// any name or (more likely) value that contains literal double quotes is likewise shown in
89-
/// its debug representation so that it is always clear if a quotation mark is just for
90-
/// display. Each name and value is otherwise shown literally.
87+
/// is shown in its Rust debug representation. This is always quoted. To decrease ambiguity,
88+
/// any name or value containing a literal double quote or newline is also shown in its debug
89+
/// representation. Names and values without such content are shown literally and not quoted.
9190
#[clap(visible_alias = "e")]
9291
Env {},
9392
}

tests/it/src/commands/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub(super) mod function {
88

99
fn repr(text: &std::ffi::OsStr) -> String {
1010
text.to_str()
11-
.filter(|s| !s.contains('"'))
11+
.filter(|s| !s.chars().any(|c| c == '"' || c == '\n'))
1212
.map(ToOwned::to_owned)
1313
.unwrap_or_else(|| format!("{text:?}"))
1414
}

0 commit comments

Comments
 (0)