Skip to content

Commit 89d57fc

Browse files
authored
fix(curlify): replace all occurrences of $ (#6354)
* replace all occurrences instead of only first occurrence
1 parent 255aa20 commit 89d57fc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/core/curlify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function curl( request ){
2727
for( let p of request.get("headers").entries() ){
2828
let [ h,v ] = p
2929
curlified.push( "-H " )
30-
curlified.push( `"${h}: ${v.replace("$", "\\$")}"` )
30+
curlified.push( `"${h}: ${v.replace(/\$/g, "\\$")}"` )
3131
isMultipartFormDataRequest = isMultipartFormDataRequest || /^content-type$/i.test(h) && /^multipart\/form-data$/i.test(v)
3232
}
3333
}
@@ -47,7 +47,7 @@ export default function curl( request ){
4747
curlified.push( "-d" )
4848
let reqBody = request.get("body")
4949
if (!Map.isMap(reqBody)) {
50-
curlified.push( JSON.stringify( request.get("body") ).replace(/\\n/g, "").replace("$", "\\$") )
50+
curlified.push( JSON.stringify( request.get("body") ).replace(/\\n/g, "").replace(/\$/g, "\\$") )
5151
} else {
5252
let curlifyToJoin = []
5353
for (let [k, v] of request.get("body").entrySeq()) {

test/unit/core/curlify.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,17 @@ describe("curlify", function () {
351351

352352
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"X-DOLLAR: token/123\\$\" -d \"CREATE (\\$props)\"")
353353
})
354+
355+
it("should escape multiple dollar signs", function () {
356+
let req = {
357+
url: "http://example.com",
358+
method: "POST",
359+
headers: { },
360+
body: "RETURN $x + $y"
361+
}
362+
363+
let curlified = curl(Im.fromJS(req))
364+
365+
expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"RETURN \\$x + \\$y\"")
366+
})
354367
})

0 commit comments

Comments
 (0)