修复bytes类型转换错误的bug

This commit is contained in:
M09Ic 2023-06-03 21:09:01 +08:00
parent 976ce55bdc
commit fc3f476fe2
4 changed files with 28 additions and 6 deletions

View File

@ -505,7 +505,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
logs.Log.Importantf("Loaded %d dictionaries and %d decorators", len(opt.Dictionaries), len(r.Fns))
if opt.Match != "" {
exp, err := expr.Compile(opt.Match)
exp, err := expr.Compile(opt.Match, expr.Patch(&bytesPatcher{}))
if err != nil {
return nil, err
}
@ -513,7 +513,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
}
if opt.Filter != "" {
exp, err := expr.Compile(opt.Filter)
exp, err := expr.Compile(opt.Filter, expr.Patch(&bytesPatcher{}))
if err != nil {
return nil, err
}
@ -535,7 +535,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
}
if express != "" {
exp, err := expr.Compile(express)
exp, err := expr.Compile(express, expr.Patch(&bytesPatcher{}))
if err != nil {
return nil, err
}

View File

@ -3,6 +3,7 @@ package internal
import (
"bytes"
"github.com/antonmedv/expr"
"github.com/antonmedv/expr/ast"
"github.com/antonmedv/expr/vm"
"github.com/chainreactors/logs"
"github.com/chainreactors/spray/pkg"
@ -276,3 +277,18 @@ func MatchWithGlobs(u string, globs []string) bool {
}
return false
}
type bytesPatcher struct{}
func (p *bytesPatcher) Visit(node *ast.Node) {
switch (*node).(type) {
case *ast.MemberNode:
ast.Patch(node, &ast.CallNode{
Callee: &ast.MemberNode{
Node: *node,
Name: "String",
Property: &ast.StringNode{Value: "String"},
},
})
}
}

View File

@ -105,9 +105,9 @@ type Baseline struct {
Url *url.URL `json:"-"`
Dir bool `json:"-"`
Chunked bool `json:"-"`
Body []byte `json:"-"`
Header []byte `json:"-"`
Raw []byte `json:"-"`
Body BS `json:"-"`
Header BS `json:"-"`
Raw BS `json:"-"`
Recu bool `json:"-"`
RecuDepth int `json:"-"`
URLs []string `json:"-"`

View File

@ -37,3 +37,9 @@ var ErrMap = map[ErrorType]string{
func (e ErrorType) Error() string {
return ErrMap[e]
}
type BS []byte
func (b BS) String() string {
return string(b)
}