Skip to content

Commit ac769d6

Browse files
authored
Escape "original command" more robustly (#41)
* Fix typo in README * Escape "original command" more robustly Fixes #35.
1 parent 81899d0 commit ac769d6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is a sister tool to [JSON-to-Go](https://mholt.github.io/json-to-go), which
77

88
### Try it
99

10-
**[Check it out!](https://mholt.github.io/curl-to-go)** It works inside your browser. Just give the code a once-over since it will need you to flush out some parts like error handling.
10+
**[Check it out!](https://mholt.github.io/curl-to-go)** It works inside your browser. Just give the code a once-over since it will need you to flesh out some parts like error handling.
1111

1212

1313
### FAQ

resources/js/curl-to-go.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function curlToGo(curl) {
1111
var err = 'if err != nil {\n\t// handle err\n}\n';
1212
var deferClose = 'defer resp.Body.Close()\n';
1313
var promo = "// Generated by curl-to-Go: https://mholt.github.io/curl-to-go";
14-
var originalCmd = `// Original command: ${curl}`;
15-
var header = `${promo}\n${originalCmd}\n`;
14+
var originalCmd = curl.split(/\r\n?|\n/).map((line) => `// ${line}`).join('\n');
15+
var header = `${promo}\n\n${originalCmd}\n\n`;
1616

1717
// List of curl flags that are boolean typed; this helps with parsing
1818
// a command like `curl -abc value` to know whether 'value' belongs to '-c'
@@ -46,7 +46,7 @@ function curlToGo(curl) {
4646
if (Object.keys(req.headers).length == 0 && !req.data.ascii && !req.data.files && !req.basicauth && !req.insecure) {
4747
return header+renderSimple(req.method, req.url);
4848
} else {
49-
return header+"\n"+renderComplex(req);
49+
return header+renderComplex(req);
5050
}
5151

5252

0 commit comments

Comments
 (0)