Skip to content

Commit bf46e18

Browse files
authored
Forbid the closing brace in text (#198)
1 parent 2fce339 commit bf46e18

8 files changed

+80
-5
lines changed

spec/fluent.ebnf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ any_char ::= [\\u{9}\\u{20}-\\u{D7FF}\\u{E000}-\\u{FFFD}]
102102
* new line.
103103
*/
104104
special_text_char ::= "{"
105+
| "}"
105106
text_char ::= any_char - special_text_char
106-
indented_char ::= text_char - "}" - "[" - "*" - "."
107+
indented_char ::= text_char - "[" - "*" - "."
107108

108109
/* String literals
109110
*

syntax/grammar.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ let any_char =
397397
*/
398398

399399
let special_text_char =
400-
string("{");
400+
either(
401+
string("{"),
402+
string("}"));
401403

402404
let text_char =
403405
and(
@@ -409,7 +411,6 @@ let indented_char =
409411
not(string(".")),
410412
not(string("*")),
411413
not(string("[")),
412-
not(string("}")),
413414
text_char);
414415

415416
/* -------------------------------------------------------------------------- */

test/fixtures/escaped_characters.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ string-escaped-unicode = {"\\u0041"}
1919
2020
## Literal braces
2121
brace-open = An opening {"{"} brace.
22-
brace-close = A closing } brace.
22+
brace-close = A closing {"}"} brace.

test/fixtures/escaped_characters.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,18 @@
259259
"elements": [
260260
{
261261
"type": "TextElement",
262-
"value": "A closing } brace."
262+
"value": "A closing "
263+
},
264+
{
265+
"type": "Placeable",
266+
"expression": {
267+
"type": "StringLiteral",
268+
"value": "}"
269+
}
270+
},
271+
{
272+
"type": "TextElement",
273+
"value": " brace."
263274
}
264275
]
265276
},

test/fixtures/placeables.ftl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
nested-placeable = {{{1}}}
22
padded-placeable = { 1 }
33
sparse-placeable = { { 1 } }
4+
5+
# ERROR Unmatched opening brace
6+
unmatched-open1 = { 1
7+
8+
# ERROR Unmatched opening brace
9+
unmatched-open2 = {{ 1 }
10+
11+
# ERROR Unmatched closing brace
12+
unmatched-close1 = 1 }
13+
14+
# ERROR Unmatched closing brace
15+
unmatched-close2 = { 1 }}

test/fixtures/placeables.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,42 @@
7272
},
7373
"attributes": [],
7474
"comment": null
75+
},
76+
{
77+
"type": "Comment",
78+
"content": "ERROR Unmatched opening brace"
79+
},
80+
{
81+
"type": "Junk",
82+
"annotations": [],
83+
"content": "unmatched-open1 = { 1\n"
84+
},
85+
{
86+
"type": "Comment",
87+
"content": "ERROR Unmatched opening brace"
88+
},
89+
{
90+
"type": "Junk",
91+
"annotations": [],
92+
"content": "unmatched-open2 = {{ 1 }\n"
93+
},
94+
{
95+
"type": "Comment",
96+
"content": "ERROR Unmatched closing brace"
97+
},
98+
{
99+
"type": "Junk",
100+
"annotations": [],
101+
"content": "unmatched-close1 = 1 }\n"
102+
},
103+
{
104+
"type": "Comment",
105+
"content": "ERROR Unmatched closing brace"
106+
},
107+
{
108+
"type": "Junk",
109+
"annotations": [],
110+
"content": "unmatched-close2 = { 1 }}\n"
75111
}
76112
]
77113
}

test/fixtures/select_expressions.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ nested-variant-list =
3434
*[two] Value
3535
}
3636
}
37+
38+
# ERROR Missing line end after variant list
39+
missing-line-end =
40+
{ 1 ->
41+
*[one] One}

test/fixtures/select_expressions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@
257257
"type": "Junk",
258258
"annotations": [],
259259
"content": "nested-variant-list =\n { 1 ->\n *[one] {\n *[two] Value\n }\n }\n"
260+
},
261+
{
262+
"type": "Comment",
263+
"content": "ERROR Missing line end after variant list"
264+
},
265+
{
266+
"type": "Junk",
267+
"annotations": [],
268+
"content": "missing-line-end =\n { 1 ->\n *[one] One}\n"
260269
}
261270
]
262271
}

0 commit comments

Comments
 (0)