From 9380f3cc06efa85751333153e6e241ea2bc554b5 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 19 Aug 2020 10:12:07 +0200 Subject: [PATCH] Allow YAML tags to be a string --- lib/core/note_serializer.dart | 2 ++ test/note_serializer_test.dart | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/core/note_serializer.dart b/lib/core/note_serializer.dart index c0b9c318..106bb83e 100644 --- a/lib/core/note_serializer.dart +++ b/lib/core/note_serializer.dart @@ -190,6 +190,8 @@ class NoteSerializer implements NoteSerializerInterface { note.tags = tags.map((t) => t.toString()).toSet(); } else if (tags is List) { note.tags = tags.map((t) => t.toString()).toSet(); + } else if (tags is String) { + note.tags = {tags}; } else { Log.e("Note Tags Decoding Failed: $tags"); } diff --git a/test/note_serializer_test.dart b/test/note_serializer_test.dart index abea0cf9..c38122df 100644 --- a/test/note_serializer_test.dart +++ b/test/note_serializer_test.dart @@ -122,5 +122,32 @@ void main() { expect(doc.props['title'], 'Why not?'); expect(doc.props['draft'], true); }); + + test('Test Non list Tag', () { + var props = LinkedHashMap.from({ + "title": "Why not?", + "draft": true, + "tags": "foo", + }); + var doc = MdYamlDoc("body", props); + + var serializer = NoteSerializer.raw(); + serializer.settings.saveTitleAsH1 = false; + + var note = Note(parent, "file-path-not-important"); + serializer.decode(doc, note); + + expect(note.body, "body"); + expect(note.title, "Why not?"); + expect(note.extraProps, {"draft": true}); + expect(note.tags, {"foo"}); + + serializer.encode(note, doc); + expect(doc.body, "body"); + expect(doc.props['title'], 'Why not?'); + expect(doc.props['draft'], true); + expect(doc.props['tags'], ['foo']); + expect(doc.props.length, 3); + }); }); }