summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-19 08:09:12 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-19 08:09:12 +0200
commita526d934cea17ff1b76ddad5c5f2934fb85c11cb (patch)
treee9fad9bb85fe265e5e8777704da6ba85b77fe122 /lib
parenteacb54ae44f655c010fdfc2b7292d24f06ffc445 (diff)
downloadcolitur-a526d934cea17ff1b76ddad5c5f2934fb85c11cb.tar.gz
colitur-a526d934cea17ff1b76ddad5c5f2934fb85c11cb.zip
fix(render): reject empty tag paths, sharpen the raw-form test
F1: test_no_raw_or_partial_form's first assertion only excluded one literal shape (Ok [Var ["{name"]]), so it could not actually catch a future raw/unescaped constructor under a different name. Replace it with an assertion of the real parse result for {{{name}}} (Ok [Var ["{name"]; Text "}"]), documented behaviour rather than a guarantee this test cannot check -- the real guarantee is structural: node has exactly four constructors and none of them is raw. F2: {{.}}, {{#}}, {{^}} and {{/}} used to parse to a Var/Section/ Inverted with an empty path, reachable but never designed. This engine has no "current context" for a bare dot to mean, so a bare-dot or empty-sigil path is now a parse error at lex time, covering all four sigil forms via one path helper. The existing "empty tag {{}}" branch is unchanged and still reachable (a fully empty body is a distinct case from a sigil with an empty path).
Diffstat (limited to 'lib')
-rw-r--r--lib/render/template.ml18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/render/template.ml b/lib/render/template.ml
index 8de91a6..3e35d53 100644
--- a/lib/render/template.ml
+++ b/lib/render/template.ml
@@ -38,13 +38,23 @@ let lex src =
let b = trim body in
if b = "" then Error "empty tag {{}}"
else
+ (* Every sigil form (var, #, ^, /) resolves a dotted path; an
+ empty path ("{{.}}", "{{#}}", "{{^}}", "{{/}}") names
+ nothing -- there is no "current context" concept for a bare
+ dot to mean, so it is a parse error rather than an invented
+ behaviour Task 3 would have to define. *)
+ let with_path ctor rest =
+ match path rest with
+ | [] -> Error "empty tag path: {{.}} and {{#}} name nothing"
+ | p -> Ok (ctor p)
+ in
match b.[0] with
- | '#' -> Ok (TOpen (path (String.sub b 1 (String.length b - 1))))
- | '^' -> Ok (TInv (path (String.sub b 1 (String.length b - 1))))
- | '/' -> Ok (TClose (path (String.sub b 1 (String.length b - 1))))
+ | '#' -> with_path (fun p -> TOpen p) (String.sub b 1 (String.length b - 1))
+ | '^' -> with_path (fun p -> TInv p) (String.sub b 1 (String.length b - 1))
+ | '/' -> with_path (fun p -> TClose p) (String.sub b 1 (String.length b - 1))
| '!' -> Ok TComment
| '>' -> Error "partials are not supported: a template may not include another file"
- | _ -> Ok (TVar (path b))
+ | _ -> with_path (fun p -> TVar p) b
in
(match tag with
| Error e -> Error e