Skip to content

Commit c6ea23d

Browse files
committed
Forbid newlines in string expressions
Partial port of projectfluent/fluent.js#135 affecting the tooling parser.
1 parent cf564c3 commit c6ea23d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

fluent/syntax/errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ def get_error_message(code, args):
4646
return 'Attributes of public messages cannot be used as selectors'
4747
if code == 'E0019':
4848
return 'Attributes of private messages cannot be used as placeables'
49+
if code == 'E0020':
50+
return 'Unterminated string expression'
4951
return code

fluent/syntax/parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,13 @@ def get_string(self, ps):
582582

583583
ps.expect_char('"')
584584

585-
ch = ps.take_char(lambda x: x != '"')
585+
ch = ps.take_char(lambda x: x != '"' and x != '\n')
586586
while ch:
587587
val += ch
588-
ch = ps.take_char(lambda x: x != '"')
588+
ch = ps.take_char(lambda x: x != '"' and x != '\n')
589+
590+
if ps.current_is('\n'):
591+
raise ParseError('E0020')
589592

590593
ps.next()
591594

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
key = { BUILTIN(key: "
22
text
33
") }
4+
//~ ERROR E0020, pos 22

0 commit comments

Comments
 (0)