Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.5

Bug #5156 Undocumented BBC
Submitted: 2005-08-19 20:27 UTC
From: justinh Assigned: jstump
Status: Closed Package: Net_Curl
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2005-08-19 20:27 UTC] justinh
Description: ------------ Between 0.2 and 1.2.0, there appears to be a BBC. Specifically, the method for how post fields are handled between the two versions has changed. In 0.2, the fields property was passed directly to curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->fields). In 1.2.0, if $this->fields is an array, it's broken into an array of "key=value", then imploded with & and passed to curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields). I believe that when curl_setopt ($ch, CURLOPT_POSTFIELDS, [array]), the [array] is urlencoded, but curl_setopt ($ch, CURLOPT_POSTFIELDS, [string]), the [string] is not urlencoded. Test script: --------------- <?php if (!empty ($_POST)) { print_r ($_POST); } else { require_once 'Net/Curl.php'; $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; $fields = array ( 'one' => 'ok', 'two' => '8c78a jc 0p8- hkF f9py8 &*_( =083-= =7<F10> io$80Y )*gY089 408Y _PHUIV(p *vH038' ); $curl = &new Net_Curl ($url); $curl->fields = $fields; $result1 = $curl->execute (); $curl->close (); $ch = curl_init ($url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $result2 = curl_exec ($ch); curl_close ($ch); echo '<pre>' . $result1 . "\n" . $result2 . '</pre>'; } ?> Expected result: ---------------- Array ( [one] => ok [two] => 8c78a jc 0p8- hkF f9py8 &*_( =083-= =7 io$80Y )*gY089 408Y _PHUIV(p *vH038 ) Array ( [one] => ok [two] => 8c78a jc 0p8- hkF f9py8 &*_( =083-= =7 io$80Y )*gY089 408Y _PHUIV(p *vH038 ) Actual result: -------------- Array ( [one] => ok [two] => 8c78a jc 0p8- hkF f9py8 [*_(_] => 083-= =7 io$80Y )*gY089 408Y _PHUIV(p *vH038 ) Array ( [one] => ok [two] => 8c78a jc 0p8- hkF f9py8 &*_( =083-= =7 io$80Y )*gY089 408Y _PHUIV(p *vH038 )

Comments

 [2005-08-19 21:01 UTC] justinh
This may not have anything to do with urlencoding actually... it may just be the unescaped & character in the fields causing the problem. The BBC still exists, however.
 [2005-08-19 21:04 UTC] jstump
http://us3.php.net/manual/en/function.curl-setopt.php#46377 Looks like I should be urlencode'ing the $val. Please take a look at line 521 in Net/Curl.php. It should look like this: $sets[] = $key . '=' . $val; Change it to this: $sets[] = $key . '=' . urlencode($val); Does that fix it? If so I'll roll a new release this weekend or early next week. I always figured curl did all the url encoding itself. What version of curl are you running (I seem to remember running into this problem while debugging Payment_Process with Net_Curl and I was double encoding).
 [2005-08-19 23:44 UTC] justinh
Yup, that fixes the problem.
 [2005-08-22 16:40 UTC] jstump
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/Net_Curl