Add request filter for intercept

This commit is contained in:
David Stotijn
2022-03-15 19:32:29 +01:00
parent d051d48941
commit f4074a8060
18 changed files with 500 additions and 69 deletions

View File

@ -3,6 +3,7 @@ package search
import (
"encoding/gob"
"regexp"
"strconv"
"strings"
)
@ -50,13 +51,17 @@ type StringLiteral struct {
}
func (sl StringLiteral) String() string {
return sl.Value
return strconv.Quote(sl.Value)
}
type RegexpLiteral struct {
*regexp.Regexp
}
func (rl RegexpLiteral) String() string {
return strconv.Quote(rl.Regexp.String())
}
func (rl RegexpLiteral) MarshalBinary() ([]byte, error) {
return []byte(rl.Regexp.String()), nil
}

View File

@ -208,7 +208,7 @@ func parseInfixExpression(p *Parser, left Expression) (Expression, error) {
return nil, fmt.Errorf("could not compile regular expression %q: %w", rightStr.Value, err)
}
right = re
right = RegexpLiteral{re}
}
}

View File

@ -94,7 +94,7 @@ func TestParseQuery(t *testing.T) {
expectedExpression: InfixExpression{
Operator: TokOpRe,
Left: StringLiteral{Value: "foo"},
Right: regexp.MustCompile("bar"),
Right: RegexpLiteral{regexp.MustCompile("bar")},
},
expectedError: nil,
},
@ -104,7 +104,7 @@ func TestParseQuery(t *testing.T) {
expectedExpression: InfixExpression{
Operator: TokOpNotRe,
Left: StringLiteral{Value: "foo"},
Right: regexp.MustCompile("bar"),
Right: RegexpLiteral{regexp.MustCompile("bar")},
},
expectedError: nil,
},
@ -197,7 +197,7 @@ func TestParseQuery(t *testing.T) {
Right: InfixExpression{
Operator: TokOpRe,
Left: StringLiteral{Value: "baz"},
Right: regexp.MustCompile("yolo"),
Right: RegexpLiteral{regexp.MustCompile("yolo")},
},
},
expectedError: nil,