ソースを参照

fix: escape `$` in curl request bodies and headers (#6245)

This address a bug where a `$` character in a request body or header
would not be properly escaped in a string in the generated curl command.

Fixes #5390
bubble
Alec Theriault 4年前
committed by GitHub
コミット
225a915cf8
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 4AEE18F83AFDEB23
2個のファイルの変更15行の追加2行の削除
  1. +2
    -2
      src/core/curlify.js
  2. +13
    -0
      test/mocha/core/curlify.js

+ 2
- 2
src/core/curlify.js ファイルの表示

@@ -26,7 +26,7 @@ export default function curl( request ){
for( let p of request.get("headers").entries() ){
let [ h,v ] = p
curlified.push( "-H " )
curlified.push( `"${h}: ${v}"` )
curlified.push( `"${h}: ${v.replace("$", "\\$")}"` )
isMultipartFormDataRequest = isMultipartFormDataRequest || /^content-type$/i.test(h) && /^multipart\/form-data$/i.test(v)
}
}
@@ -44,7 +44,7 @@ export default function curl( request ){
}
} else {
curlified.push( "-d" )
curlified.push( JSON.stringify( request.get("body") ).replace(/\\n/g, "") )
curlified.push( JSON.stringify( request.get("body") ).replace(/\\n/g, "").replace("$", "\\$") )
}
} else if(!request.get("body") && request.get("method") === "POST") {
curlified.push( "-d" )


+ 13
- 0
test/mocha/core/curlify.js ファイルの表示

@@ -319,4 +319,17 @@ describe("curlify", function () {
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -d {\"id\":\"123\",\"file\":{\"name\":\"file.txt\",\"type\":\"text/plain\"}}")
})
})

it("should escape dollar signs in headers and request body", function () {
let req = {
url: "http://example.com",
method: "POST",
headers: { "X-DOLLAR": "token/123$" },
body: "CREATE ($props)"
}

let curlified = curl(Im.fromJS(req))

expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"X-DOLLAR: token/123\\$\" -d \"CREATE (\\$props)\"")
})
})

読み込み中…
キャンセル
保存