From 39658641b1df212f9d4abb7d3c7155da8b80fa6b Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 23 Jan 2025 17:06:38 -0600 Subject: [PATCH] Update http2curl.go --- http2curl.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/http2curl.go b/http2curl.go index df21c19..6e2c1b9 100644 --- a/http2curl.go +++ b/http2curl.go @@ -26,6 +26,10 @@ func bashEscape(str string) string { return `'` + strings.Replace(str, `'`, `'\''`, -1) + `'` } +func bracketEscape(str string) string { + return strings.Replace(strings.Replace(str, `[`, `\[`, -1), `]`, `\]`, -1) +} + // GetCurlCommand returns a CurlCommand corresponding to an http.Request func GetCurlCommand(req *http.Request) (*CurlCommand, error) { if req.URL == nil { @@ -77,7 +81,7 @@ func GetCurlCommand(req *http.Request) (*CurlCommand, error) { command.append("-H", bashEscape(fmt.Sprintf("%s: %s", k, strings.Join(req.Header[k], " ")))) } - command.append(bashEscape(requestURL)) + command.append(bashEscape(bracketEscape(requestURL))) command.append("--compressed")