File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
Expand file tree Collapse file tree 3 files changed +20
-1
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,6 +556,12 @@ describe('Query parsing', () => {
556556 expect ( new Query ( 'short mode\nfull' ) . queryLayoutOptions . shortMode ) . toEqual ( false ) ;
557557 } ) ;
558558
559+ it ( 'should cope with missing end-of-line character in query ending with continuation character - #3137' , ( ) => {
560+ const query = new Query ( 'path includes query.md \\' ) ;
561+ expect ( query . filters . length ) . toEqual ( 1 ) ;
562+ expect ( query . filters [ 0 ] . instruction ) . toEqual ( 'path includes query.md' ) ;
563+ } ) ;
564+
559565 describe ( 'should include instruction in parsing error messages' , ( ) => {
560566 function getQueryError ( source : string ) {
561567 return new Query ( source , new TasksFile ( 'Example Path.md' ) ) . error ;
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