mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-13 01:36:15 +02:00
builtins.match: Improve error message for bad regular expression
Issue #1331.
This commit is contained in:
parent
b01d62285c
commit
e46090edb1
1 changed files with 23 additions and 16 deletions
|
@ -1709,12 +1709,15 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
|
|||
‘null’ or a list containing substring matches. */
|
||||
static void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||
{
|
||||
std::regex regex(state.forceStringNoCtx(*args[0], pos), std::regex::extended);
|
||||
auto re = state.forceStringNoCtx(*args[0], pos);
|
||||
|
||||
try {
|
||||
|
||||
std::regex regex(re, std::regex::extended);
|
||||
|
||||
PathSet context;
|
||||
const std::string str = state.forceString(*args[1], context, pos);
|
||||
|
||||
|
||||
std::smatch match;
|
||||
if (!std::regex_match(str, match, regex)) {
|
||||
mkNull(v);
|
||||
|
@ -1730,6 +1733,10 @@ static void prim_match(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
else
|
||||
mkString(*(v.listElems()[i] = state.allocValue()), match[i + 1].str().c_str());
|
||||
}
|
||||
|
||||
} catch (std::regex_error &) {
|
||||
throw EvalError("invalid regular expression ‘%s’, at %s", re, pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue