aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/print.hh
diff options
context:
space:
mode:
authorAlex Ameen <alex.ameen.tx@gmail.com>2023-05-09 09:45:12 -0500
committerAlex Ameen <alex.ameen.tx@gmail.com>2023-05-09 09:45:12 -0500
commitb72bc4a972fe568744d98b89d63adcd504cb586c (patch)
treec68afe392499121d6f5872eb2a7fef6c3b5ddb41 /src/libexpr/print.hh
parent4539ab530ad23a8558512f784bd72c4cd0e72f13 (diff)
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.
Diffstat (limited to 'src/libexpr/print.hh')
-rw-r--r--src/libexpr/print.hh6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libexpr/print.hh b/src/libexpr/print.hh
index f9cfc3964..3b72ae201 100644
--- a/src/libexpr/print.hh
+++ b/src/libexpr/print.hh
@@ -36,6 +36,12 @@ namespace nix {
std::ostream & printAttributeName(std::ostream & o, std::string_view s);
/**
+ * Returns `true' is a string is a reserved keyword which requires quotation
+ * when printing attribute set field names.
+ */
+ bool isReservedKeyword(const std::string_view str);
+
+ /**
* Print a string as an identifier in the Nix expression language syntax.
*
* FIXME: "identifier" is ambiguous. Identifiers do not have a single