Skip to content

Commit

Permalink
Escape single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
lloesche committed Jul 25, 2024
1 parent 544333e commit 38f4e8b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"net/http"
"strings"

"github.com/sirupsen/logrus"
)
Expand All @@ -17,6 +18,10 @@ type SearchRequest struct {
WithEdges bool `json:"with_edges"`
}

func escapeSingleQuotes(s string) string {
return strings.ReplaceAll(s, "'", "'\\''")
}

func SearchGraph(apiEndpoint, fixJWT, workspaceID, searchStr string, withEdges bool) (<-chan interface{}, <-chan error) {
results := make(chan interface{})
errs := make(chan error, 1)
Expand Down Expand Up @@ -49,7 +54,8 @@ func SearchGraph(apiEndpoint, fixJWT, workspaceID, searchStr string, withEdges b
Secure: true,
})

curlCommand := fmt.Sprintf("curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/ndjson' -H 'Cookie: session_token=%s' -d '%s' %s", fixJWT, string(requestBody), url)
escapedRequestBody := escapeSingleQuotes(string(requestBody))
curlCommand := fmt.Sprintf("curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/ndjson' -H 'Cookie: session_token=%s' -d '%s' %s", fixJWT, escapedRequestBody, url)
logrus.Debugln("Equivalent curl command:", curlCommand)

client := &http.Client{}
Expand Down

0 comments on commit 38f4e8b

Please sign in to comment.