Skip to content

Commit 086c96c

Browse files
committed
Requests: apply patch / PR 499
1 parent 0025264 commit 086c96c

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
/**
4+
* Exception for an invalid argument passed.
5+
*
6+
* @package Requests
7+
*/
8+
class Requests_Exception_InvalidArgument extends InvalidArgumentException {}

src/wp-includes/Requests/Transport/cURL.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ public function __destruct() {
130130
* @return string Raw HTTP result
131131
*/
132132
public function request($url, $headers = array(), $data = array(), $options = array()) {
133+
if (!is_array($data) && !is_string($data)) {
134+
if ($data === null) {
135+
$data = '';
136+
} elseif (is_int($data) || is_float($data)) {
137+
$data = (string) $data;
138+
} else {
139+
throw new Requests_Exception_InvalidArgument(
140+
sprintf(
141+
'%s: Argument #%d (%s) must be of type %s, %s given',
142+
__METHOD__,
143+
3,
144+
'$data',
145+
'array|string',
146+
gettype($data)
147+
)
148+
);
149+
}
150+
}
151+
133152
$this->hooks = $options['hooks'];
134153

135154
$this->setup_handle($url, $headers, $data, $options);

src/wp-includes/Requests/Transport/fsockopen.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ class Requests_Transport_fsockopen implements Requests_Transport {
5656
* @return string Raw HTTP result
5757
*/
5858
public function request($url, $headers = array(), $data = array(), $options = array()) {
59+
if (!is_array($data) && !is_string($data)) {
60+
if ($data === null) {
61+
$data = '';
62+
} elseif (is_int($data) || is_float($data)) {
63+
$data = (string) $data;
64+
} else {
65+
throw new Requests_Exception_InvalidArgument(
66+
sprintf(
67+
'%s: Argument #%d (%s) must be of type %s, %s given',
68+
__METHOD__,
69+
3,
70+
'$data',
71+
'array|string',
72+
gettype($data)
73+
)
74+
);
75+
}
76+
}
77+
5978
$options['hooks']->dispatch('fsockopen.before_request');
6079

6180
$url_parts = parse_url($url);

0 commit comments

Comments
 (0)