Skip to content

Commit da6a6a8

Browse files
committed
Use split instead of splitlines to serialize comments (fixes #119)
`splitlines` returns `[]` for empty strings, which is not what we want, use `split` instead. This matches what `@fluent.syntax` does on the js side.
1 parent e2cfea0 commit da6a6a8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

fluent.syntax/fluent/syntax/serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def serialize_entry(self, entry, state=0):
6464
def serialize_comment(comment, prefix="#"):
6565
prefixed = "\n".join([
6666
prefix if len(line) == 0 else "{} {}".format(prefix, line)
67-
for line in comment.content.splitlines(False)
67+
for line in comment.content.split("\n")
6868
])
6969
# Add the trailing line break.
7070
return '{}\n'.format(prefixed)

fluent.syntax/tests/syntax/test_serializer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def test_comment_message(self):
115115
# A multiline
116116
# message comment.
117117
foo = Foo
118+
#
119+
bar = Bar
118120
"""
119121
self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
120122

@@ -128,6 +130,10 @@ def test_comment_group(self):
128130
## group comment.
129131
130132
bar = Bar
133+
134+
##
135+
136+
baz = Baz
131137
"""
132138
self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
133139

0 commit comments

Comments
 (0)