* Fixed Bug #64310 (weak etags W/"abc" are quoted as "W/"abc"")
authorMichael Wallner <mike@php.net>
Sat, 2 Mar 2013 20:13:19 +0000 (20:13 +0000)
committerMichael Wallner <mike@php.net>
Sat, 2 Mar 2013 20:13:19 +0000 (20:13 +0000)
http_request_api.c
package.xml
php_http.h

index 1b0c59e..b6e4034 100644 (file)
@@ -872,12 +872,29 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        }
        /* etag */
        if ((zoption = http_request_option(request, options, "etag", IS_STRING)) && Z_STRLEN_P(zoption)) {
-               zend_bool is_quoted = !((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"'));
+               zend_bool is_quoted;
                phpstr header;
-               
+
                phpstr_init(&header);
-               phpstr_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", range_req?"If-Match":"If-None-Match", Z_STRVAL_P(zoption));
+               phpstr_appendf(&header, "%s: ", range_req?"If-Match":"If-None-Match");
+               if ((Z_STRVAL_P(zoption)[0] == '"') && (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] == '"')) {
+                       /* properly quoted etag */
+                       phpstr_append(&header, Z_STRVAL_P(zoption), Z_STRLEN_P(zoption));
+               } else if ((Z_STRVAL_P(zoption)[0] == 'W') && (Z_STRVAL_P(zoption)[1] == '/')) {
+                       /* weak etag */
+                       if ((Z_STRLEN_P(zoption) > 3) && (Z_STRVAL_P(zoption)[2] == '"') && (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] == '"')) {
+                               /* quoted */
+                               phpstr_append(&header, Z_STRVAL_P(zoption), Z_STRLEN_P(zoption));
+                       } else {
+                               /* unquoted */
+                               phpstr_appendf(&header, "W/\"%s\"", Z_STRVAL_P(zoption) + 2);
+                       }
+               } else {
+                       /* assume unquoted etag */
+                       phpstr_appendf(&header, "\"%s\"", Z_STRVAL_P(zoption));
+               }
                phpstr_fix(&header);
+
                request->_cache.headers = curl_slist_append(request->_cache.headers, PHPSTR_VAL(&header));
                phpstr_dtor(&header);
        }
index 1440438..4adfb6f 100644 (file)
@@ -28,9 +28,9 @@ support. Parallel requests are available for PHP 5 and greater.
   <email>mike@php.net</email>
   <active>yes</active>
  </lead>
- <date>2012-04-02</date>
+ <date>2013-03-02</date>
  <version>
-  <release>1.7.4</release>
+  <release>1.7.5dev</release>
   <api>1.7.0</api>
  </version>
  <stability>
@@ -39,7 +39,7 @@ support. Parallel requests are available for PHP 5 and greater.
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
-* Fixed Bug #61372 (build fails with "undefined symbol Z_ADDREF_P)
+* Fixed Bug #64310 (weak etags W/"abc" are quoted as "W/"abc"")
 ]]></notes>
  <contents>
   <dir name="/">
index 0762c07..023be4f 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef PHP_EXT_HTTP_H
 #define PHP_EXT_HTTP_H
 
-#define PHP_HTTP_VERSION "1.7.4"
+#define PHP_HTTP_VERSION "1.7.5dev"
 
 #ifdef HAVE_CONFIG_H
 #      include "config.h"