commit 8e4d6609acde3fa7125f64dfbb7ef29a8e6e3f69
parent b842d1516027d1764c0fa2016ef4391dbe696757
Author: Noam Preil <noam@pixelhero.dev>
Date: Thu, 1 Dec 2022 04:39:57 -0500
strings::template: reject left braces
Signed-off-by: Noam Preil <noam@pixelhero.dev>
Diffstat:
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/strings/template/README b/strings/template/README
@@ -7,7 +7,7 @@ names must be alphanumeric ASCII characters (i.e. for which [[ascii::isalnum]]
returns true). A literal "$" may be printed by using it twice: "$$". Variables
may also be used with braces, i.e. ${variable}, so that they can be placed
immediately next to alphanumeric characters; such variables may include
-non-alphanumeric characters other than '}'.
+non-alphanumeric characters other than '{' and '}'.
const src = "Hello, $user! Your balance is $$$balance.\n";
const template = template::compile(src)!;
diff --git a/strings/template/template.ha b/strings/template/template.ha
@@ -132,7 +132,9 @@ fn parse_variable(
};
if (brace) {
- if (rn != '}') {
+ if (rn == '{') {
+ return errors::invalid;
+ } else if (rn != '}') {
strio::appendrune(buf, rn)!;
} else {
break;