filters: supporting alternative characters for quote

The regexp syntax can have some nasty characters to handle quoting
correctly, in practice. In certain scenarios a double quote works well,
but it can affect readability for certain regexps. This introduces a
quoting mode that treats `/` and `|` as a double quote to make the
quoting in regular expressions more familiar and readable.

This change is introduced in a backwards compatible manner, so existing
regexp quoting is not affected.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-12-04 17:12:41 -08:00
parent 617c63de06
commit 4dfcf60bec
5 changed files with 343 additions and 11 deletions

View File

@@ -135,6 +135,11 @@ func TestFilters(t *testing.T) {
corpus[8],
},
},
{
name: "LabelValueNoAltQuoting",
input: "labels.|foo|==omg_asdf.asdf-qwer",
errString: "filters: parse error: [labels. >|||< foo|==omg_asdf.asdf-qwer]: invalid quote encountered",
},
{
name: "Name",
input: "name==bar",
@@ -178,6 +183,27 @@ func TestFilters(t *testing.T) {
corpus[7],
},
},
{
name: "RegexpQuotedValue",
input: "other~=/[abc]+/,name!=foo",
expected: []interface{}{
corpus[6],
corpus[7],
},
},
{
name: "RegexpQuotedValue",
input: "other~=/[abc]{1,2}/,name!=foo",
expected: []interface{}{
corpus[6],
corpus[7],
},
},
{
name: "RegexpQuotedValueGarbage",
input: "other~=/[abc]{0,1}\"\\//,name!=foo",
// valid syntax, but doesn't match anything
},
{
name: "NameAndLabelValue",
input: "name==bar,labels.bar==true",