Merge pull request #1755 from projectdiscovery/issue-1713-gitlab-report

Adding HexOrString helper
This commit is contained in:
Sandeep Singh 2022-03-28 16:46:57 +05:30 committed by GitHub
commit 5364d91b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -54,7 +54,7 @@ func MarkdownDescription(event *output.ResultEvent) string { // TODO remove the
if event.Request != "" {
builder.WriteString("\n**Request**\n\n```http\n")
builder.WriteString(event.Request)
builder.WriteString(types.ToHexOrString(event.Request))
builder.WriteString("\n```\n")
}
if event.Response != "" {
@ -135,7 +135,7 @@ func MarkdownDescription(event *output.ResultEvent) string { // TODO remove the
if event.CURLCommand != "" {
builder.WriteString("\n**CURL Command**\n```\n")
builder.WriteString(event.CURLCommand)
builder.WriteString(types.ToHexOrString(event.CURLCommand))
builder.WriteString("\n```")
}

View File

@ -3,10 +3,12 @@
package types
import (
"encoding/hex"
"fmt"
"strconv"
"strings"
"github.com/asaskevich/govalidator"
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
)
@ -75,6 +77,20 @@ func ToString(data interface{}) string {
}
}
func ToHexOrString(data interface{}) string {
switch s := data.(type) {
case string:
if govalidator.IsASCII(s) {
return s
}
return hex.Dump([]byte(s))
case []byte:
return hex.Dump(s)
default:
return fmt.Sprintf("%v", data)
}
}
// ToStringSlice casts an interface to a []string type.
func ToStringSlice(i interface{}) []string {
var a []string