Skip to content

Commit ea1bdc9

Browse files
committed
Model: Don't add empty bodies
1 parent 1a99b3a commit ea1bdc9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/PHPDraft/Model/HTTPRequest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,23 @@ public function get_curl_command($base_url, $additional = [])
137137
$type = (isset($this->headers['Content-Type'])) ? $this->headers['Content-Type'] : null;
138138

139139
$options[] = '-X' . $this->method;
140-
if (is_string($this->body)) {
141-
$options[] = '--data-binary "' . $this->body . '"';
140+
if (empty($this->body)){
141+
//NO-OP
142+
}elseif (is_string($this->body)) {
143+
$options[] = '--data-binary ' . escapeshellarg($this->body);
142144
} elseif (is_array($this->body)) {
143-
$options[] = '--data-binary "' . join('', $this->body) . '"';
145+
$options[] = '--data-binary ' . escapeshellarg(join('', $this->body));
144146
} elseif (is_subclass_of($this->struct, StructureElement::class)) {
145147
foreach ($this->struct->value as $body) {
146-
$options[] = '--data-binary "' . strip_tags($body->print_request($type)) . '"';
148+
$options[] = '--data-binary ' . escapeshellarg(strip_tags($body->print_request($type)));
147149
}
148150
}
149151
foreach ($this->headers as $header => $value) {
150-
$options[] = '-H "' . $header . ': ' . $value . '"';
152+
$options[] = '-H ' . escapeshellarg($header . ': ' . $value);
151153
}
152154
$options = array_merge($options, $additional);
153155

154-
return htmlspecialchars('curl ' . join(' ', $options) . ' "' . $this->parent->build_url($base_url, true) . '"');
156+
return htmlspecialchars('curl ' . join(' ', $options) . ' ' . escapeshellarg($this->parent->build_url($base_url, true)));
155157
}
156158

157159

0 commit comments

Comments
 (0)