File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff 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 || / ^ c o n t e n t - t y p e $ / i. test ( h ) && / ^ m u l t i p a r t \/ f o r m - d a t a $ / 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 ( ) ) {
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments