mirror of
https://github.com/NixOS/nix
synced 2025-06-29 23:13:14 +02:00
Don't allow appending a non-absolute path to the root of a source tree
This avoids an inconsistency where a '/' is implicitly inserted when you append to the root of a source tree, but not when you append to any other path.
This commit is contained in:
parent
d162222f25
commit
6d104bbbac
2 changed files with 10 additions and 1 deletions
|
@ -1998,6 +1998,11 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||||
} else if (firstType == nPath) {
|
} else if (firstType == nPath) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
auto part = state.coerceToString(i_pos, *vTmp, context, false, false);
|
auto part = state.coerceToString(i_pos, *vTmp, context, false, false);
|
||||||
|
if (sSize <= 1 && !hasPrefix(*part, "/"))
|
||||||
|
state.throwEvalError(i_pos,
|
||||||
|
"cannot append non-absolute path '%1%' to '%2%' (hint: change it to '/%1%')",
|
||||||
|
(std::string) *part, accessor->root().to_string(),
|
||||||
|
env, *this);
|
||||||
sSize += part->size();
|
sSize += part->size();
|
||||||
s.emplace_back(std::move(part));
|
s.emplace_back(std::move(part));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,10 @@ source common.sh
|
||||||
mkdir -p $TEST_ROOT/foo
|
mkdir -p $TEST_ROOT/foo
|
||||||
echo bla > $TEST_ROOT/foo/bar
|
echo bla > $TEST_ROOT/foo/bar
|
||||||
|
|
||||||
[[ $(nix eval --raw --impure --expr "builtins.readFile (builtins.toString (builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; } + \"bar\"))") = bla ]]
|
[[ $(nix eval --raw --impure --expr "builtins.readFile (builtins.toString (builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; } + \"/bar\"))") = bla ]]
|
||||||
|
|
||||||
|
[[ $(nix eval --raw --impure --expr "builtins.readFile (builtins.toString (builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; } + \"/b\" + \"ar\"))") = bla ]]
|
||||||
|
|
||||||
|
(! nix eval --raw --impure --expr "builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; } + \"bar\"")
|
||||||
|
|
||||||
[[ $(nix eval --json --impure --expr "builtins.readDir (builtins.toString (builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; }))") = '{"bar":"regular"}' ]]
|
[[ $(nix eval --json --impure --expr "builtins.readDir (builtins.toString (builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; }))") = '{"bar":"regular"}' ]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue