Skip to content

Commit 5cb0e01

Browse files
committed
fix: '\' at end of last line in query no longer discards the instruction
Fixes #3137.
1 parent 2973c6b commit 5cb0e01

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Query/Scanner.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ export function continueLines(input: string): Statement[] {
6969

7070
let currentStatementRaw = '';
7171
let currentStatementProcessed = '';
72-
for (const inputLine of input.split('\n')) {
72+
73+
// See https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3137.
74+
// Issue #3137 revealed that if the last line of the query ended in
75+
// a backslash, this function returned without saved the final
76+
// instruction.
77+
// The simplest way to prevent this is to add an extra end-of-line
78+
// to the end of the query, which will get ignored when not needed:
79+
const inputWithGuaranteedFinalEOL = input + '\n';
80+
for (const inputLine of inputWithGuaranteedFinalEOL.split('\n')) {
7381
const adjustedLine = adjustLine(inputLine, continuePreviousLine);
7482
if (continuePreviousLine) {
7583
currentStatementRaw += '\n' + inputLine;

tests/Query/Query.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ describe('Query parsing', () => {
556556
expect(new Query('short mode\nfull').queryLayoutOptions.shortMode).toEqual(false);
557557
});
558558

559-
it.failing('should cope with missing end-of-line character in query ending with continuation character', () => {
560-
// See https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3137
559+
it('should cope with missing end-of-line character in query ending with continuation character - #3137', () => {
561560
const query = new Query('path includes query.md \\');
562561
expect(query.filters.length).toEqual(1);
563562
expect(query.filters[0].instruction).toEqual('path includes query.md');

tests/Query/Scanner.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ describe('continue_lines', () => {
150150
expect(continueLinesFlattened(text)).toEqual('description includes one two three four five six');
151151
});
152152

153+
it('should preserve last instruction in query that ends in a continuation line = #3137', () => {
154+
const text = 'due today \\';
155+
expect(continueLinesFlattened(text)).toEqual('due today');
156+
});
157+
153158
it('visualise continue_lines', () => {
154159
const output = `
155160
input:

0 commit comments

Comments
 (0)