Skip to content

Commit

Permalink
Handle non-utf8 evaluation result
Browse files Browse the repository at this point in the history
  • Loading branch information
xzfc committed Apr 28, 2020
1 parent 194c560 commit 9bd1649
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ fn run_nix_shell(inp: &NixShellInput) -> NixShellOutput {
if !exec.status.success() {
exit(1);
}
let output = String::from_utf8(exec.stdout).expect("failed to decode");
// Path to .drv file is always in ASCII, so no information is lost.
let output = String::from_utf8_lossy(&exec.stdout);
let output: serde_json::Value =
serde_json::from_str(&output).expect("failed to parse json");

// The first key of the toplevel object contains the path to .drv file.
let (drv, _) = output.as_object().unwrap().into_iter().next().unwrap();

drv.clone()
};

Expand Down
18 changes: 18 additions & 0 deletions tests/t10-non-utf8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,21 @@ run cached-nix-shell ./tmp/shellhook.nix --pure --keep VAR_IN \
--run 'printf "%s\n" "$VAR_OUT"'
check_contains '^out:VAR_IN=aM-pb\^@$'
unset VAR_IN


# Non-utf8 evaluation result
put ./tmp/evaluation.nix << EOF # unquoted
with import <nixpkgs> { };
mkShell {
"VAR1" = "A${F0}B";
"VAR${F1}2" = "CD";
}
EOF

run cached-nix-shell ./tmp/evaluation.nix --pure \
--run 'env -0 | LANG=C grep -z "^VAR1=" | cat -v'
check_contains '^VAR1=AM-pB\^@$'

run cached-nix-shell ./tmp/evaluation.nix --pure \
--run 'env -0 | LANG=C grep -z "^VAR.2=" | cat -v'
check_contains '^VARM-q2=CD\^@$'

0 comments on commit 9bd1649

Please sign in to comment.