Index: trunk/extensions/ExternalData/ED_Utils.php |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | } |
52 | 52 | |
53 | 53 | static function parseParams( $params ) { |
54 | | - $args = Array(); |
| 54 | + $args = array(); |
55 | 55 | foreach ( $params as $param ) { |
56 | 56 | $param = preg_replace ( "/\s\s+/", ' ', $param ); // whitespace |
57 | 57 | $param_parts = explode( "=", $param, 2 ); |
— | — | @@ -68,8 +68,22 @@ |
69 | 69 | */ |
70 | 70 | static function paramToArray( $arg, $lowercaseKeys = false, $lowercaseValues = false ) { |
71 | 71 | $arg = preg_replace ( "/\s\s+/", ' ', $arg ); // whitespace |
72 | | - $keyValuePairs = explode( ',', $arg ); |
73 | | - $returnArray = Array(); |
| 72 | + |
| 73 | + // Split text on commas, except for commas found within quotes |
| 74 | + // and parentheses. Code copied from: |
| 75 | + // http://stackoverflow.com/questions/1373735/regexp-split-string-by-commas-and-spaces-but-ignore-the-inside-quotes-and-parent#1381895 |
| 76 | + $pattern = <<<END |
| 77 | + / |
| 78 | + [,\s]++ |
| 79 | + (?=(?:(?:[^"]*+"){2})*+[^"]*+$) |
| 80 | + (?=(?:(?:[^']*+'){2})*+[^']*+$) |
| 81 | + (?=(?:[^()]*+\([^()]*+\))*+[^()]*+$) |
| 82 | + /x |
| 83 | +END; |
| 84 | + // " - fix for color highlighting in vi :) |
| 85 | + $keyValuePairs = preg_split( $pattern, $arg ); |
| 86 | + |
| 87 | + $returnArray = array(); |
74 | 88 | foreach ( $keyValuePairs as $keyValuePair ) { |
75 | 89 | $keyAndValue = explode( '=', $keyValuePair, 2 ); |
76 | 90 | if ( count( $keyAndValue ) == 2 ) { |
— | — | @@ -214,7 +228,7 @@ |
215 | 229 | $rows = self::searchDB( $db, $from, $columns, $where, $options ); |
216 | 230 | $db->close(); |
217 | 231 | |
218 | | - $values = Array(); |
| 232 | + $values = array(); |
219 | 233 | foreach ( $rows as $row ) { |
220 | 234 | foreach ( $columns as $column ) { |
221 | 235 | $values[$column][] = $row[$column]; |
— | — | @@ -234,7 +248,7 @@ |
235 | 249 | echo ( wfMsgExt( "externaldata-db-invalid-query", array( 'parse', 'escape' ) ) ); |
236 | 250 | return false; |
237 | 251 | } else { |
238 | | - $rows = Array(); |
| 252 | + $rows = array(); |
239 | 253 | while ( $row = $db->fetchRow( $result ) ) { |
240 | 254 | // Create a new row object, that uses the |
241 | 255 | // passed-in column names as keys, so that |