From 977b9e794af57d4dd8f28a8191ac3d38ca4c8224 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Mon, 5 Jul 2021 15:48:29 +0200 Subject: Specify block scope resolution (#125) --- specs/~inheritance.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/specs/~inheritance.yml b/specs/~inheritance.yml index 07fa081..5a24ba8 100644 --- a/specs/~inheritance.yml +++ b/specs/~inheritance.yml @@ -224,3 +224,14 @@ tests: partials: parent: "{{$foo}}default content{{/foo}}" expected: default content + + - name: Block scope + desc: Scope of a substituted block is evaluated in the context of the parent template + data: + fruit: apples + nested: + fruit: bananas + template: "{{ Date: Mon, 5 Jul 2021 16:13:50 +0200 Subject: Update JSON accordingly --- specs/~inheritance.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/specs/~inheritance.json b/specs/~inheritance.json index fedb34b..0a6878b 100644 --- a/specs/~inheritance.json +++ b/specs/~inheritance.json @@ -230,6 +230,21 @@ "parent": "{{$foo}}default content{{/foo}}" }, "expected": "default content" + }, + { + "name": "Block scope", + "desc": "Scope of a substituted block is evaluated in the context of the parent template", + "data": { + "fruit": "apples", + "nested": { + "fruit": "bananas" + } + }, + "template": "{{ Date: Tue, 22 Mar 2022 08:36:44 +0000 Subject: add test: comment content colliding with variable Currently, an implementation treating comments as undefined variables successfully passes all tests, because both undefined variables and comments render to empty string. This clarifies the behavior: A comment MUST NOT render into anything, under any circumstances. This includes the case where a variable with the same name as the comment content is defined. The test data is designed in a way to trigger any possible name collision, including white spaces, a leading exclamation mark (!). --- specs/comments.json | 12 ++++++++++++ specs/comments.yml | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/specs/comments.json b/specs/comments.json index 60a4929..924ed46 100644 --- a/specs/comments.json +++ b/specs/comments.json @@ -89,6 +89,18 @@ }, "template": "12345 {{! Comment Block! }} 67890", "expected": "12345 67890" + }, + { + "name": "Variable Name Collision", + "desc": "Comments must never render, even if variable with same name exists.", + "data": { + "! comment": 1, + "! comment ": 2, + "!comment": 3, + "comment": 4 + }, + "template": "comments never show: >{{! comment }}<", + "expected": "comments never show: ><" } ] } diff --git a/specs/comments.yml b/specs/comments.yml index 7b14c7f..3bad09f 100644 --- a/specs/comments.yml +++ b/specs/comments.yml @@ -101,3 +101,9 @@ tests: data: { } template: '12345 {{! Comment Block! }} 67890' expected: '12345 67890' + + - name: Variable Name Collision + desc: Comments must never render, even if variable with same name exists. + data: { '! comment': 1, '! comment ': 2, '!comment': 3, 'comment': 4} + template: 'comments never show: >{{! comment }}<' + expected: 'comments never show: ><' -- cgit v1.2.1