From 34412e91de0a9b7eabd2d0ea0f197aa99154a223 Mon Sep 17 00:00:00 2001 From: Michele Bertasi Date: Wed, 2 Nov 2022 14:37:46 +0100 Subject: [PATCH] Revert "check for undesirable quotes" --- internal/engine/filter/convert.go | 23 +++++++---------------- internal/engine/filter/convert_test.go | 18 ------------------ 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/internal/engine/filter/convert.go b/internal/engine/filter/convert.go index e541e33a..c55ad3ff 100644 --- a/internal/engine/filter/convert.go +++ b/internal/engine/filter/convert.go @@ -104,11 +104,9 @@ func generateNode(node *parser.Node) (Criteria, error) { func generateLeaf(leaf *parser.Leaf) (Criteria, error) { needEscape := leaf.Function != parser.FunctionQuery && !leaf.IsRaw - query, err := joinStrings(needEscape, leaf.Args...) - if err != nil { - return Criteria{}, err - } + query := joinStrings(needEscape, leaf.Args...) if len(leaf.Args) > 1 { + var err error if query, err = groupWithOperation(query, leaf.Grouping); err != nil { return Criteria{}, err } @@ -176,11 +174,9 @@ func generateNodeAsString(node *parser.Node) (string, error) { func generateLeafAsString(leaf *parser.Leaf) (string, error) { needEscape := leaf.Function != parser.FunctionQuery && !leaf.IsRaw - query, err := joinStrings(needEscape, leaf.Args...) - if err != nil { - return "", err - } + query := joinStrings(needEscape, leaf.Args...) if len(leaf.Args) > 1 { + var err error if query, err = groupWithOperation(query, leaf.Grouping); err != nil { return "", err } @@ -230,16 +226,11 @@ func joinQueries(f1, f2 string) string { return fmt.Sprintf("%s %s", f1, f2) } -func joinStrings(escape bool, a ...string) (string, error) { +func joinStrings(escape bool, a ...string) string { if escape { - for _, a := range a { - if strings.Contains(a, `"`) { - return "", fmt.Errorf("invalid quote in %q", a) - } - } - return joinEscaped(a...), nil + return joinEscaped(a...) } - return strings.Join(a, " "), nil + return strings.Join(a, " ") } func joinEscaped(a ...string) string { diff --git a/internal/engine/filter/convert_test.go b/internal/engine/filter/convert_test.go index ab38834d..773359a9 100644 --- a/internal/engine/filter/convert_test.go +++ b/internal/engine/filter/convert_test.go @@ -363,21 +363,3 @@ func TestActions(t *testing.T) { assert.Nil(t, err) assert.Equal(t, expected, got) } - -func TestDoubleQuoteError(t *testing.T) { - rules := []parser.Rule{ - { - Criteria: &parser.Leaf{ - Function: parser.FunctionSubject, - Args: []string{`a"b`}, - IsRaw: false, - }, - Actions: parser.Actions{ - // action choice is irrelevant - Labels: []string{"l1"}, - }, - }, - } - _, err := FromRules(rules) - assert.ErrorContains(t, err, "invalid quote") -}