mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	fix lexer to parse correctly quoted empty strings, #1825
This commit is contained in:
		
							parent
							
								
									855c5e0e67
								
							
						
					
					
						commit
						858072cc10
					
				@ -87,14 +87,16 @@ describe("Lexer expression", () => {
 | 
			
		||||
            .toEqual(["#label", "*=*", "text"]);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("simple label operator with in quotes and without", () => {
 | 
			
		||||
    it("simple label operator with in quotes", () => {
 | 
			
		||||
        expect(lex("#label*=*'text'").expressionTokens)
 | 
			
		||||
            .toEqual([
 | 
			
		||||
                {token: "#label", inQuotes: false, startIndex: 0, endIndex: 5},
 | 
			
		||||
                {token: "*=*", inQuotes: false, startIndex: 6, endIndex: 8},
 | 
			
		||||
                {token: "text", inQuotes: true, startIndex: 10, endIndex: 13}
 | 
			
		||||
            ]);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("simple label operator with param without quotes", () => {
 | 
			
		||||
        expect(lex("#label*=*text").expressionTokens)
 | 
			
		||||
            .toEqual([
 | 
			
		||||
                {token: "#label", inQuotes: false, startIndex: 0, endIndex: 5},
 | 
			
		||||
@ -103,6 +105,16 @@ describe("Lexer expression", () => {
 | 
			
		||||
            ]);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("simple label operator with empty string param", () => {
 | 
			
		||||
        expect(lex("#label = ''").expressionTokens)
 | 
			
		||||
            .toEqual([
 | 
			
		||||
                {token: "#label", inQuotes: false, startIndex: 0, endIndex: 5},
 | 
			
		||||
                {token: "=", inQuotes: false, startIndex: 7, endIndex: 7},
 | 
			
		||||
                // weird case for empty strings which ends up with endIndex < startIndex :-(
 | 
			
		||||
                {token: "", inQuotes: true, startIndex: 10, endIndex: 9}
 | 
			
		||||
            ]);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("note. prefix also separates fulltext from expression", () => {
 | 
			
		||||
        expect(lex(`hello fulltext note.labels.capital = Prague`).expressionTokens.map(t => t.token))
 | 
			
		||||
            .toEqual(["note", ".", "labels", ".", "capital", "=", "prague"]);
 | 
			
		||||
 | 
			
		||||
@ -21,8 +21,8 @@ function lex(str) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function finishWord(endIndex) {
 | 
			
		||||
        if (currentWord === '') {
 | 
			
		||||
    function finishWord(endIndex, createAlsoForEmptyWords = false) {
 | 
			
		||||
        if (currentWord === '' && !createAlsoForEmptyWords) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -71,7 +71,7 @@ function lex(str) {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else if (quotes === chr) {
 | 
			
		||||
                finishWord(i - 1);
 | 
			
		||||
                finishWord(i - 1, true);
 | 
			
		||||
 | 
			
		||||
                quotes = false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user