12
12
13
13
const { format } = require ( '../../helpers/format' )
14
14
const CodeBuilder = require ( '../../helpers/code-builder' )
15
+ const { phpSqEscape } = require ( './helpers' )
15
16
16
17
module . exports = function ( source , options ) {
17
18
const opts = Object . assign ( {
@@ -78,7 +79,16 @@ module.exports = function (source, options) {
78
79
79
80
curlOptions . forEach ( function ( option ) {
80
81
if ( ! ~ [ null , undefined ] . indexOf ( option . value ) ) {
81
- curlopts . push ( format ( '%s => %s,' , option . name , option . escape ? JSON . stringify ( option . value ) : option . value ) )
82
+ curlopts . push (
83
+ format ( '%s => %s,' ,
84
+ option . name ,
85
+ option . escape && typeof option . value === 'string'
86
+ ? `'${ phpSqEscape ( option . value ) } '`
87
+ : option . escape
88
+ ? JSON . stringify ( option . value )
89
+ : option . value
90
+ )
91
+ )
82
92
}
83
93
} )
84
94
@@ -88,12 +98,12 @@ module.exports = function (source, options) {
88
98
} )
89
99
90
100
if ( cookies . length ) {
91
- curlopts . push ( format ( ' CURLOPT_COOKIE => "%s",' , cookies . join ( '; ' ) ) )
101
+ curlopts . push ( format ( " CURLOPT_COOKIE => '%s'" , phpSqEscape ( cookies . join ( '; ' ) ) ) )
92
102
}
93
103
94
104
// construct cookies
95
105
const headers = Object . keys ( source . headersObj ) . sort ( ) . map ( function ( key ) {
96
- return format ( '" %s: %qd"' , key , source . headersObj [ key ] )
106
+ return format ( "' %s: %s'" , phpSqEscape ( key ) , phpSqEscape ( source . headersObj [ key ] ) )
97
107
} )
98
108
99
109
if ( headers . length ) {
@@ -113,9 +123,9 @@ module.exports = function (source, options) {
113
123
. push ( 'if ($err) {' )
114
124
115
125
if ( opts . namedErrors ) {
116
- code . push ( 1 , ' echo array_flip(get_defined_constants(true)[" curl" ])[$err];' )
126
+ code . push ( 1 , " echo array_flip(get_defined_constants(true)[' curl' ])[$err];" )
117
127
} else {
118
- code . push ( 1 , ' echo " cURL Error #:" . $err;' )
128
+ code . push ( 1 , " echo ' cURL Error #:' . $err;" )
119
129
}
120
130
121
131
code . push ( '} else {' )
0 commit comments