Permalink
Browse files

MDL-37217 files: Stricter type check for curl options

  • Loading branch information...
1 parent 1dd6835 commit 91c8cf9963ae27d0cb51681c3cd15537b45321af @FMCorz FMCorz committed Feb 19, 2013
Showing with 18 additions and 8 deletions.
  1. +14 −8 lib/filelib.php
  2. +4 −0 lib/upgrade.txt
View
@@ -2935,14 +2935,22 @@ public function resetcookie() {
}
/**
- * Set curl options
+ * Set curl options.
*
- * @param array $options If array is null, this function will
- * reset the options to default value.
+ * Do not use the curl constants to define the options, pass a string
+ * corresponding to that constant. Ie. to set CURLOPT_MAXREDIRS, pass
+ * array('CURLOPT_MAXREDIRS' => 10) or array('maxredirs' => 10) to this method.
+ *
+ * @param array $options If array is null, this function will reset the options to default value.
+ * @return void
+ * @throws coding_exception If an option uses constant value instead of option name.
*/
public function setopt($options = array()) {
if (is_array($options)) {
- foreach($options as $name => $val){
+ foreach ($options as $name => $val){
+ if (!is_string($name)) {
+ throw new coding_exception('Curl options should be defined using strings, not constant values.');
+ }
if (stripos($name, 'CURLOPT_') === false) {
$name = strtoupper('CURLOPT_'.$name);
}
@@ -3067,11 +3075,9 @@ private function apply_opt($curl, $options) {
var_dump($this->header);
}
- // set options
+ // Set options.
foreach($this->options as $name => $val) {
- if (is_string($name)) {
- $name = constant(strtoupper($name));
- }
+ $name = constant(strtoupper($name));
curl_setopt($curl, $name, $val);
}
return $curl;
View
@@ -18,6 +18,10 @@ information provided here is intended especially for developers.
only partially deletes data, so wherever it was called extra code was needed to
perform the whole deletion process. The function course_delete_module now takes care
of the whole process.
+* curl::setopt() does not accept constant values any more. As it never worked properly,
+ we decided to make the type check stricter. Now, the keys of the array pass must be a string
+ corresponding to the curl constant name.
+
YUI changes:
* M.util.help_icon has been deprecated. Code should be updated to use moodle-core-popuphelp

0 comments on commit 91c8cf9

Please sign in to comment.