diff --git a/pkg/drafts/drafts.go b/pkg/drafts/drafts.go index 68c303d..7cbf7fb 100644 --- a/pkg/drafts/drafts.go +++ b/pkg/drafts/drafts.go @@ -6,6 +6,7 @@ import ( ) const tagSeparator = "|||" +const recordSeparator = "\x1e" type ActionRunResult struct { UUID string `json:"uuid"` @@ -333,7 +334,7 @@ func queryDrafts(scope, queryString string, filter Filter, opt QueryOptions) ([] if output is "" then set output to line_out else - set output to output & linefeed & line_out + set output to output & (ASCII character 30) & line_out end if end repeat return output @@ -348,7 +349,7 @@ end tell`, scope, whereClause) return []Draft{}, nil } - lines := strings.Split(output, "\n") + lines := strings.Split(output, recordSeparator) drafts := make([]Draft, 0, len(lines)) for _, line := range lines { if line != "" { diff --git a/pkg/drafts/drafts_test.go b/pkg/drafts/drafts_test.go index 43b8f92..11b7dba 100644 --- a/pkg/drafts/drafts_test.go +++ b/pkg/drafts/drafts_test.go @@ -324,6 +324,38 @@ func TestQueryFlagged(t *testing.T) { assert.EqualSlice(t, []string{a}, uuids) } +func TestQueryMultilineContent(t *testing.T) { + tag := rand() + multiline := "Line one\nLine two\nLine three" + + a, err := Create(multiline, CreateOptions{Tags: []string{tag}}) + requireNoError(t, err) + b, err := Create("single line", CreateOptions{Tags: []string{tag}}) + requireNoError(t, err) + defer func() { + requireNoError(t, Trash(a)) + requireNoError(t, Trash(b)) + }() + + // Get confirms the multiline draft exists + draft, err := Get(a) + requireNoError(t, err) + assert.Equal(t, multiline, draft.Content) + + // Query must also find it + results, err := Query("", FilterInbox, QueryOptions{Tags: []string{tag}}) + requireNoError(t, err) + uuids := getUUIDs(results) + assertSameUUIDs(t, []string{a, b}, uuids) + + // Verify the multiline draft's content is intact after round-tripping through Query + for _, d := range results { + if d.UUID == a { + assert.Equal(t, multiline, d.Content) + } + } +} + // ---- Workspace tests -------------------------------------------------------- func TestQueryWorkspace(t *testing.T) {