mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Merge b21b3ad851
into b9b510d692
This commit is contained in:
commit
4244736326
3 changed files with 27 additions and 6 deletions
|
@ -41,10 +41,10 @@ namespace nix {
|
|||
* Miscellaneous
|
||||
*************************************************************/
|
||||
|
||||
static inline Value * mkString(EvalState & state, const std::csub_match & match)
|
||||
static inline Value * mkString(EvalState & state, const std::csub_match & match, const NixStringContext & context)
|
||||
{
|
||||
Value * v = state.allocValue();
|
||||
v->mkString({match.first, match.second});
|
||||
v->mkString({match.first, match.second}, context);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -4395,7 +4395,7 @@ void prim_match(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
|||
if (!match[i + 1].matched)
|
||||
v2 = &state.vNull;
|
||||
else
|
||||
v2 = mkString(state, match[i + 1]);
|
||||
v2 = mkString(state, match[i + 1], context);
|
||||
v.mkList(list);
|
||||
|
||||
} catch (std::regex_error & e) {
|
||||
|
@ -4479,7 +4479,7 @@ void prim_split(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
|||
const auto & match = *i;
|
||||
|
||||
// Add a string for non-matched characters.
|
||||
list[idx++] = mkString(state, match.prefix());
|
||||
list[idx++] = mkString(state, match.prefix(), context);
|
||||
|
||||
// Add a list for matched substrings.
|
||||
const size_t slen = match.size() - 1;
|
||||
|
@ -4490,14 +4490,14 @@ void prim_split(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
|||
if (!match[si + 1].matched)
|
||||
v2 = &state.vNull;
|
||||
else
|
||||
v2 = mkString(state, match[si + 1]);
|
||||
v2 = mkString(state, match[si + 1], context);
|
||||
}
|
||||
|
||||
(list[idx++] = state.allocValue())->mkList(list2);
|
||||
|
||||
// Add a string for non-matched suffix characters.
|
||||
if (idx == 2 * len)
|
||||
list[idx++] = mkString(state, match.suffix());
|
||||
list[idx++] = mkString(state, match.suffix(), context);
|
||||
}
|
||||
|
||||
assert(idx == 2 * len + 1);
|
||||
|
|
1
tests/functional/lang/eval-okay-match-context.exp
Normal file
1
tests/functional/lang/eval-okay-match-context.exp
Normal file
|
@ -0,0 +1 @@
|
|||
[ true true true ]
|
20
tests/functional/lang/eval-okay-match-context.nix
Normal file
20
tests/functional/lang/eval-okay-match-context.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
let
|
||||
|
||||
s = "${builtins.derivation {
|
||||
name = "test";
|
||||
builder = "/bin/sh";
|
||||
system = "x86_64-linux";
|
||||
}}";
|
||||
|
||||
c = builtins.getContext s;
|
||||
|
||||
matchRes = builtins.match ".*(-).*" s;
|
||||
|
||||
splitRes = builtins.split "(-)" s;
|
||||
|
||||
in
|
||||
[
|
||||
(c == builtins.getContext (builtins.head matchRes))
|
||||
(c == builtins.getContext (builtins.head splitRes))
|
||||
(c == builtins.getContext (builtins.head (builtins.elemAt splitRes 1)))
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue