Skip to content

Commit

Permalink
Revert "check for undesirable quotes"
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrt committed Nov 2, 2022
1 parent 4d85916 commit 34412e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
23 changes: 7 additions & 16 deletions internal/engine/filter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 0 additions & 18 deletions internal/engine/filter/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 34412e9

Please sign in to comment.