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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user