diff --git a/lib/storage/serializers.dart b/lib/storage/serializers.dart index 3313366f..7d8aee4f 100644 --- a/lib/storage/serializers.dart +++ b/lib/storage/serializers.dart @@ -78,11 +78,16 @@ class MarkdownYAMLSerializer implements NoteSerializer { var yamlText = str.substring(4, endYamlPos); var map = _parseYamlText(yamlText); + var body = ""; var bodyBeginingPos = endYamlPos + endYamlStr.length; - if (str[bodyBeginingPos] == '\n') { - bodyBeginingPos += 1; + if (bodyBeginingPos < str.length) { + if (str[bodyBeginingPos] == '\n') { + bodyBeginingPos += 1; + } + if (bodyBeginingPos < str.length) { + body = str.substring(bodyBeginingPos); + } } - var body = str.substring(bodyBeginingPos); return NoteData(body, map); } diff --git a/test/serializers_test.dart b/test/serializers_test.dart index 16efa178..55735314 100644 --- a/test/serializers_test.dart +++ b/test/serializers_test.dart @@ -152,7 +152,7 @@ Alright."""; expect(actualStr, note.body); }); - test('Only YAML Header without \\n', () { + test('Only YAML Header without \\n at end', () { var str = """--- foo: bar ---"""; @@ -166,5 +166,21 @@ foo: bar var actualStr = serializer.encode(note); expect(actualStr, str + '\n\n'); }); + + test('Only YAML Header with \\n at end', () { + var str = """--- +foo: bar +--- +"""; + + var serializer = MarkdownYAMLSerializer(); + var note = serializer.decode(str); + + expect("", note.body); + expect({"foo": "bar"}, note.props); + + var actualStr = serializer.encode(note); + expect(actualStr, str + '\n'); + }); }); }