Skip to content

Commit

Permalink
fix json deserialization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Feb 27, 2023
1 parent 9949883 commit 27fefe5
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 10 deletions.
6 changes: 5 additions & 1 deletion v2/pkg/model/types/userAgent/user_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/operators/extractors/extractor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/operators/matchers/matchers_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/protocols/common/generators/attack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/protocols/dns/dns_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/protocols/headless/engine/action_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/protocols/http/http_method_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions v2/pkg/protocols/http/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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())
}

Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/protocols/network/network_input_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 27fefe5

Please sign in to comment.