File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed
Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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' ) ;
Original file line number Diff line number Diff 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 = `
155160input:
You can’t perform that action at this time.
0 commit comments