--- a/cross-channel-l10n/mozxchannel/merge.py
+++ b/cross-channel-l10n/mozxchannel/merge.py
@@ -43,9 +43,17 @@ def merge_two(newer, older):
def serialize(entity):
snippet = entity.all
# Normalize _inline_ whitespace around the entity. This is needed
# for when an entity has whitespace in the last blank line following
# it. This may happen at the EOF. Without normalization entities
# appended after such entity would be incorrectly indented.
- return snippet.strip(" \t")
+ snippet = snippet.strip(" \t")
+
+ # Ensure that the last character after normalization is a newline. This
+ # prevents problems in scenarios opposite to above: when entities are
+ # appended after an entity with no EOL at the end.
+ if snippet[-1] != "\n":
+ snippet += "\n"
+
+ return snippet
--- a/cross-channel-l10n/tests/test-merge-whitespace.py
+++ b/cross-channel-l10n/tests/test-merge-whitespace.py
@@ -29,8 +29,20 @@ foo = Foo 2
bar = Bar 2
""")
self.assertEqual(
merge_channels(self.name, *channels), """
foo = Foo 1
bar = Bar 1
""")
+
+ def test_no_eol(self):
+ channels = ("""
+foo = Foo 1""", """
+foo = Foo 2
+bar = Bar 2
+""")
+ self.assertEqual(
+ merge_channels(self.name, *channels), """
+foo = Foo 1
+bar = Bar 2
+""")