Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --data-raw support #35

Merged
merged 7 commits into from
Oct 18, 2021
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions resources/js/curl-to-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ function curlToPHP(curl) {

var req = extractRelevantPieces(cmd);

var code = promo+"\n"+start;
var code = start;
code += 'curl_setopt($ch, CURLOPT_URL, '+phpExpandEnv(req.url)+');\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n';
if( req.url.substring(0, 5) == "https" ) {
code += 'curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\n';
}

if (req.headers.length == 0 && !req.data.ascii && !req.data.files && !req.data.multipart && !req.basicauth && !req.compressed) {
return code+renderSimple(req.method);
Expand Down Expand Up @@ -153,7 +156,7 @@ function curlToPHP(curl) {
// render PHP code to put all the data in the body, concatenating if necessary
if (ioReaders.length == 1 && typeof varName == 'undefined') {
//If variable have code ".. -d attributes='{...", delete quotes.
ioReaders[0] = ioReaders[0].replace(/\=[\'\"]\{([^$]+)\}[\'\"]/, '={$1}');
ioReaders[0] = ioReaders[0].replace(/\=[\']\{([^$]+)\}[']/, '={$1}');
php += 'curl_setopt($ch, CURLOPT_POSTFIELDS, '+ioReaders[0]+');\n';
} else if (ioReaders.length > 0) {
php += '$post = array(\n ';
Expand Down Expand Up @@ -263,6 +266,8 @@ function curlToPHP(curl) {
loadData(cmd.data);
if (cmd['data-binary'])
loadData(cmd['data-binary']);
if (cmd['data-raw'])
loadData(cmd['data-raw']);
if (cmd.F)
loadData(cmd.F, true);
if (cmd.form)
Expand Down Expand Up @@ -334,7 +339,7 @@ function curlToPHP(curl) {
// phpEsc escapes characters in s so that it is safe to use s in
// a "quoted string" in a PHP program
function phpEsc(s) {
return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
return s.replace(/\\/g, '\\\\').replace(/"/g, '"');
}
}

Expand Down