Re: cvs: pear /Net_URL URL.php

From: Date: Sun, 29 Sep 2002 20:18:49 +0000
Subject: Re: cvs: pear /Net_URL URL.php
References: 1  Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-6757@lists.php.net to get a copy of this message
Richard Heyes wrote:
Sorry about that. Do you have a problem with the patches?
I can't seem to reproduce any error with the URL you supplied before the patch is applied.
That particular url returns data irregardless, so you do not get an error, but depending on the query string of a get method request, html or wsdl is returned, a very important distinction. The issue starts with the use of parse_str, which does not create any result of query_string == 'wsdl', and continues with the expectation that query string data is an array. However, my patch does not go far enough in fixing this issue. The query string 'xxx&yyy=2&zzz' would fail, resulting in a query string in the request being 'yyy=2'. Below is a patch to deal with this correctly (cleans up some whitespace also). Regards, Shane diff -u -u -r1.17 URL.php --- URL.php 29 Sep 2002 00:16:08 -0000 1.17 +++ URL.php 29 Sep 2002 20:11:44 -0000 @@ -244,13 +244,15 @@
         if (!empty($this->querystring) &&
             is_array($this->querystring)) {
             foreach ($this->querystring as $name => $value) {
- if (is_array($value)) { - foreach ($value as $k => $v) { - $querystring[] = sprintf('%s[%s]=%s', $name, $k, $v); - } - } else {
-                	$querystring[] = $name . '=' . $value;
- }
+                if (is_array($value)) {
+                    foreach ($value as $k => $v) {
+                        $querystring[] = sprintf('%s[%s]=%s', $name, $k, $v);
+                    }
+                } else if (!is_null($value)) {
+                    $querystring[] = $name . '=' . $value;
+                } else {
+                    $querystring[] = $name;
+                }
             }
             $querystring = implode('&', $querystring);
         } else {
@@ -269,21 +271,31 @@
     */
     function _parseRawQuerystring($querystring)
     {
-        parse_str($querystring, $qs);
+        $this->parse_querystr($querystring, $qs);
-        if (!$qs) return $querystring;
         foreach ($qs as $key => $value) {
- if (is_array($value)) { - foreach ($value as $k => $v) { - $value[$k] = rawurlencode($v); - } - $qs[$key] = $value; - } else {
-	            $qs[$key] = rawurlencode($value);
- }
+            if (is_array($value)) {
+                foreach ($value as $k => $v) {
+                    $value[$k] = rawurlencode($v);
+                }
+                $qs[$key] = $value;
+            } else if (!is_null($value)) {
+                $qs[$key] = rawurlencode($value);
+            } else {
+                $qs[$key] = NULL;
+            }
         }
         return $qs;
+    }
+
+    function parse_querystr($querystring, &$result)
+    {
+        $parts = explode('&',$querystring);
+        foreach ($parts as $part) {
+            $nv = explode('=',$part);
+            $result[$nv[0]] = isset($nv[1])?$nv[1]:NULL;
+        }
     }
} ?>

« previous php.pear.cvs (#6757) next »