Note serializer: Add yet another edge case

This commit is contained in:
Vishesh Handa
2019-12-01 16:43:13 +01:00
parent 41526868ff
commit 702da72a51
2 changed files with 25 additions and 4 deletions

View File

@ -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 (bodyBeginingPos < str.length) {
if (str[bodyBeginingPos] == '\n') {
bodyBeginingPos += 1;
}
var body = str.substring(bodyBeginingPos);
if (bodyBeginingPos < str.length) {
body = str.substring(bodyBeginingPos);
}
}
return NoteData(body, map);
}

View File

@ -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');
});
});
}