diff options
author | Michael Muré <batolettre@gmail.com> | 2021-05-24 09:47:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-24 09:47:55 +0200 |
commit | 9ded45fe65c9a3af37dc05015a78d5782002e249 (patch) | |
tree | a2da60f07da4d66e7d434826edaf212c592d7c19 /webui/src/__tests__ | |
parent | 0cee27665b410dd22e3d075f7179c138bac166ab (diff) | |
parent | 7446a20db8907acedbd14ddcc6a99de577268c1c (diff) | |
download | git-bug-9ded45fe65c9a3af37dc05015a78d5782002e249.tar.gz |
Merge pull request #658 from GlancingMind/fix-webui-quoted-filter-parameters
WebUI: Fix quoted filter strings
Diffstat (limited to 'webui/src/__tests__')
-rw-r--r-- | webui/src/__tests__/query.ts | 121 |
1 files changed, 104 insertions, 17 deletions
diff --git a/webui/src/__tests__/query.ts b/webui/src/__tests__/query.ts index 2f04817c..97ec75a6 100644 --- a/webui/src/__tests__/query.ts +++ b/webui/src/__tests__/query.ts @@ -7,49 +7,136 @@ it('parses a simple query', () => { }); it('parses a query with multiple filters', () => { - expect(parse('foo:bar baz:foo-bar')).toEqual({ + expect(parse(`foo:bar baz:foo-bar`)).toEqual({ foo: ['bar'], baz: ['foo-bar'], }); + + expect(parse(`label:abc freetext`)).toEqual({ + label: [`abc`], + freetext: [''], + }); + + expect(parse(`label:abc with "quotes" 'in' freetext`)).toEqual({ + label: [`abc`], + with: [''], + '"quotes"': [''], + "'in'": [''], + freetext: [''], + }); }); it('parses a quoted query', () => { - expect(parse('foo:"bar"')).toEqual({ - foo: ['bar'], + expect(parse(`foo:"bar"`)).toEqual({ + foo: [`"bar"`], }); - expect(parse("foo:'bar'")).toEqual({ - foo: ['bar'], + expect(parse(`foo:'bar'`)).toEqual({ + foo: [`'bar'`], + }); + + expect(parse(`label:'multi word label'`)).toEqual({ + label: [`'multi word label'`], + }); + + expect(parse(`label:"multi word label"`)).toEqual({ + label: [`"multi word label"`], + }); + + expect(parse(`label:'multi word label with "nested" quotes'`)).toEqual({ + label: [`'multi word label with "nested" quotes'`], + }); + + expect(parse(`label:"multi word label with 'nested' quotes"`)).toEqual({ + label: [`"multi word label with 'nested' quotes"`], + }); + + expect(parse(`label:"with:quoated:colon"`)).toEqual({ + label: [`"with:quoated:colon"`], + }); + + expect(parse(`label:'name ends after this ->' quote'`)).toEqual({ + label: [`'name ends after this ->'`], + "quote'": [``], }); - expect(parse('foo:\'bar "nested" quotes\'')).toEqual({ - foo: ['bar "nested" quotes'], + expect(parse(`label:"name ends after this ->" quote"`)).toEqual({ + label: [`"name ends after this ->"`], + 'quote"': [``], }); - expect(parse("foo:'escaped\\' quotes'")).toEqual({ - foo: ["escaped' quotes"], + expect(parse(`label:'this ->"<- quote belongs to label name'`)).toEqual({ + label: [`'this ->"<- quote belongs to label name'`], + }); + + expect(parse(`label:"this ->'<- quote belongs to label name"`)).toEqual({ + label: [`"this ->'<- quote belongs to label name"`], + }); + + expect(parse(`label:'names end with'whitespace not with quotes`)).toEqual({ + label: [`'names end with'whitespace`], + not: [``], + with: [``], + quotes: [``], + }); + + expect(parse(`label:"names end with"whitespace not with quotes`)).toEqual({ + label: [`"names end with"whitespace`], + not: [``], + with: [``], + quotes: [``], + }); +}); + +it('should not escape nested quotes', () => { + expect(parse(`foo:'do not escape this ->'<- quote'`)).toEqual({ + foo: [`'do not escape this ->'<-`], + "quote'": [``], + }); + + expect(parse(`foo:'do not escape this ->"<- quote'`)).toEqual({ + foo: [`'do not escape this ->"<- quote'`], + }); + + expect(parse(`foo:"do not escape this ->"<- quote"`)).toEqual({ + foo: [`"do not escape this ->"<-`], + 'quote"': [``], + }); + + expect(parse(`foo:"do not escape this ->'<- quote"`)).toEqual({ + foo: [`"do not escape this ->'<- quote"`], }); }); it('parses a query with repetitions', () => { - expect(parse('foo:bar foo:baz')).toEqual({ + expect(parse(`foo:bar foo:baz`)).toEqual({ foo: ['bar', 'baz'], }); }); it('parses a complex query', () => { - expect(parse('foo:bar foo:baz baz:"foobar" idont:\'know\'')).toEqual({ + expect(parse(`foo:bar foo:baz baz:"foobar" idont:'know'`)).toEqual({ foo: ['bar', 'baz'], - baz: ['foobar'], - idont: ['know'], + baz: [`"foobar"`], + idont: [`'know'`], }); }); +it('parses a key:value:value query', () => { + expect(parse(`meta:github:"https://github.com/MichaelMure/git-bug"`)).toEqual( + { + meta: [`github:"https://github.com/MichaelMure/git-bug"`], + } + ); +}); + it('quotes values', () => { - expect(quote('foo')).toEqual('foo'); - expect(quote('foo bar')).toEqual('"foo bar"'); - expect(quote('foo "bar"')).toEqual(`'foo "bar"'`); - expect(quote(`foo "bar" 'baz'`)).toEqual(`"foo \\"bar\\" 'baz'"`); + expect(quote(`foo`)).toEqual(`foo`); + expect(quote(`foo bar`)).toEqual(`"foo bar"`); + expect(quote(`foo "bar"`)).toEqual(`"foo "bar""`); + expect(quote(`foo 'bar'`)).toEqual(`"foo "bar""`); + expect(quote(`'foo'`)).toEqual(`"foo"`); + expect(quote(`foo "bar" 'baz'`)).toEqual(`"foo "bar" "baz""`); }); it('stringifies params', () => { |