fix json deserialization issues

dev
王一之 2023-02-27 14:15:51 +08:00
parent 994988357a
commit 27fefe59d3
9 changed files with 46 additions and 10 deletions

View File

@ -87,7 +87,11 @@ func (userAgentHolder *UserAgentHolder) UnmarshalYAML(unmarshal func(interface{}
}
func (userAgentHolder *UserAgentHolder) UnmarshalJSON(data []byte) error {
computedUserAgent, err := toUserAgent(strings.Trim(string(data), `"`))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedUserAgent, err := toUserAgent(s)
if err != nil {
return err
}

View File

@ -100,7 +100,11 @@ func (holder *ExtractorTypeHolder) UnmarshalYAML(unmarshal func(interface{}) err
}
func (holder *ExtractorTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toExtractorTypes(strings.Trim(string(data), "\""))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toExtractorTypes(s)
if err != nil {
return err
}

View File

@ -107,7 +107,11 @@ func (holder *MatcherTypeHolder) UnmarshalYAML(unmarshal func(interface{}) error
}
func (holder *MatcherTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toMatcherTypes(strings.Trim(string(data), "\""))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toMatcherTypes(s)
if err != nil {
return err
}

View File

@ -89,7 +89,11 @@ func (holder *AttackTypeHolder) UnmarshalYAML(unmarshal func(interface{}) error)
}
func (holder *AttackTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toAttackType(strings.Trim(string(data), "\""))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toAttackType(s)
if err != nil {
return err
}

View File

@ -117,7 +117,11 @@ func (holder *DNSRequestTypeHolder) UnmarshalYAML(unmarshal func(interface{}) er
}
func (holder *DNSRequestTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toDNSRequestTypes(strings.Trim(string(data), "\""))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toDNSRequestTypes(s)
if err != nil {
return err
}

View File

@ -199,7 +199,11 @@ func (holder *ActionTypeHolder) UnmarshalYAML(unmarshal func(interface{}) error)
}
func (holder *ActionTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toActionTypes(strings.Trim(string(data), `"`))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toActionTypes(s)
if err != nil {
return err
}

View File

@ -117,7 +117,11 @@ func (holder *HTTPMethodTypeHolder) UnmarshalYAML(unmarshal func(interface{}) er
}
func (holder *HTTPMethodTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toHTTPMethodTypes(strings.Trim(string(data), "\""))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toHTTPMethodTypes(s)
if err != nil {
return err
}

View File

@ -79,7 +79,11 @@ func (holder *SignatureTypeHolder) UnmarshalYAML(unmarshal func(interface{}) err
}
func (holder *SignatureTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toSignatureType(strings.Trim(string(data), "\""))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toSignatureType(s)
if err != nil {
return err
}
@ -88,7 +92,7 @@ func (holder *SignatureTypeHolder) UnmarshalJSON(data []byte) error {
return nil
}
func (holder *SignatureTypeHolder) MarshalJSON() ([]byte, error) {
func (holder SignatureTypeHolder) MarshalJSON() ([]byte, error) {
return json.Marshal(holder.Value.String())
}

View File

@ -94,7 +94,11 @@ func (holder *NetworkInputTypeHolder) UnmarshalYAML(unmarshal func(interface{})
}
func (holder *NetworkInputTypeHolder) UnmarshalJSON(data []byte) error {
computedType, err := toNetworkInputTypes(strings.Trim(string(data), `"`))
s := strings.Trim(string(data), `"`)
if s == "" {
return nil
}
computedType, err := toNetworkInputTypes(s)
if err != nil {
return err
}