mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
libexpr: quote reserved keys when printing
This fixes a bug in commands like `nix eval' which would emit invalid attribute sets if they contained reserved keywords such as "assert", "let", etc. These keywords will not be quoted when printed, making them valid expressions. All keywords recognized by the lexer are quoted except "or", which does not require quotation.
This commit is contained in:
parent
4539ab530a
commit
b72bc4a972
4 changed files with 33 additions and 4 deletions
|
@ -94,7 +94,6 @@ RootValue allocRootValue(Value * v)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Value::print(const SymbolTable & symbols, std::ostream & str,
|
||||
std::set<const void *> * seen) const
|
||||
{
|
||||
|
@ -122,7 +121,13 @@ void Value::print(const SymbolTable & symbols, std::ostream & str,
|
|||
else {
|
||||
str << "{ ";
|
||||
for (auto & i : attrs->lexicographicOrder(symbols)) {
|
||||
str << symbols[i->name] << " = ";
|
||||
// Quote reserved keywords so that the output can be
|
||||
// re-evaluated later without upsetting the lexer.
|
||||
if (isReservedKeyword(symbols[i->name])) {
|
||||
str << "\"" << symbols[i->name] << "\" = ";
|
||||
} else {
|
||||
str << symbols[i->name] << " = ";
|
||||
}
|
||||
i->value->print(symbols, str, seen);
|
||||
str << "; ";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue