Author: fabien
Date: 2010-04-28 08:33:02 +0200 (Wed, 28 Apr 2010)
New Revision: 29285

Modified:
   branches/1.3/lib/request/sfWebRequest.class.php
   branches/1.3/test/unit/request/sfWebRequestTest.php
   branches/1.4/lib/request/sfWebRequest.class.php
   branches/1.4/test/unit/request/sfWebRequestTest.php
Log:
[1.3, 1.4] fixed incorrect splitting of Accept-* headers (closes #8591)

Modified: branches/1.3/lib/request/sfWebRequest.class.php
===================================================================
--- branches/1.3/lib/request/sfWebRequest.class.php     2010-04-28 01:01:07 UTC 
(rev 29284)
+++ branches/1.3/lib/request/sfWebRequest.class.php     2010-04-28 06:33:02 UTC 
(rev 29285)
@@ -615,15 +615,18 @@
       // Cut off any q-value that might come after a semi-colon
       if ($pos = strpos($value, ';'))
       {
-        $q     = (float) trim(substr($value, $pos + 3));
-        $value = trim(substr($value, 0, $pos));
+        $q     = (float) trim(substr($value, strpos($value, '=') + 1));
+        $value = substr($value, 0, $pos);
       }
       else
       {
         $q = 1;
       }
 
-      $values[$value] = $q;
+      if (0 < $q)
+      {
+        $values[trim($value)] = $q;
+      }
     }
 
     arsort($values);

Modified: branches/1.3/test/unit/request/sfWebRequestTest.php
===================================================================
--- branches/1.3/test/unit/request/sfWebRequestTest.php 2010-04-28 01:01:07 UTC 
(rev 29284)
+++ branches/1.3/test/unit/request/sfWebRequestTest.php 2010-04-28 06:33:02 UTC 
(rev 29285)
@@ -10,7 +10,7 @@
 
 require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
 
-$t = new lime_test(55);
+$t = new lime_test(57);
 
 class myRequest extends sfWebRequest
 {
@@ -82,6 +82,8 @@
 $t->is($request->splitHttpAcceptHeader('a,b,c'), array('c', 'b', 'a'), 
'->splitHttpAcceptHeader() returns an array of values');
 $t->is($request->splitHttpAcceptHeader('a,b;q=0.7,c;q=0.3'), array('a', 'b', 
'c'), '->splitHttpAcceptHeader() strips the q value');
 $t->is($request->splitHttpAcceptHeader('a;q=0.1,b,c;q=0.3'), array('b', 'c', 
'a'), '->splitHttpAcceptHeader() sorts values by the q value');
+$t->is($request->splitHttpAcceptHeader('a; q=0.1, b, c; q=0.3'), array('b', 
'c', 'a'), '->splitHttpAcceptHeader() trims whitespaces');
+$t->is($request->splitHttpAcceptHeader('a; q=0, b'), array('b'), 
'->splitHttpAcceptHeader() removes values when q = 0 (as per the RFC)');
 
 // ->getRequestFormat() ->setRequestFormat()
 $t->diag('->getRequestFormat() ->setRequestFormat()');

Modified: branches/1.4/lib/request/sfWebRequest.class.php
===================================================================
--- branches/1.4/lib/request/sfWebRequest.class.php     2010-04-28 01:01:07 UTC 
(rev 29284)
+++ branches/1.4/lib/request/sfWebRequest.class.php     2010-04-28 06:33:02 UTC 
(rev 29285)
@@ -600,15 +600,18 @@
       // Cut off any q-value that might come after a semi-colon
       if ($pos = strpos($value, ';'))
       {
-        $q     = (float) trim(substr($value, $pos + 3));
-        $value = trim(substr($value, 0, $pos));
+        $q     = (float) trim(substr($value, strpos($value, '=') + 1));
+        $value = substr($value, 0, $pos);
       }
       else
       {
         $q = 1;
       }
 
-      $values[$value] = $q;
+      if (0 < $q)
+      {
+        $values[trim($value)] = $q;
+      }
     }
 
     arsort($values);

Modified: branches/1.4/test/unit/request/sfWebRequestTest.php
===================================================================
--- branches/1.4/test/unit/request/sfWebRequestTest.php 2010-04-28 01:01:07 UTC 
(rev 29284)
+++ branches/1.4/test/unit/request/sfWebRequestTest.php 2010-04-28 06:33:02 UTC 
(rev 29285)
@@ -10,7 +10,7 @@
 
 require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
 
-$t = new lime_test(55);
+$t = new lime_test(57);
 
 class myRequest extends sfWebRequest
 {
@@ -82,6 +82,8 @@
 $t->is($request->splitHttpAcceptHeader('a,b,c'), array('c', 'b', 'a'), 
'->splitHttpAcceptHeader() returns an array of values');
 $t->is($request->splitHttpAcceptHeader('a,b;q=0.7,c;q=0.3'), array('a', 'b', 
'c'), '->splitHttpAcceptHeader() strips the q value');
 $t->is($request->splitHttpAcceptHeader('a;q=0.1,b,c;q=0.3'), array('b', 'c', 
'a'), '->splitHttpAcceptHeader() sorts values by the q value');
+$t->is($request->splitHttpAcceptHeader('a; q=0.1, b, c; q=0.3'), array('b', 
'c', 'a'), '->splitHttpAcceptHeader() trims whitespaces');
+$t->is($request->splitHttpAcceptHeader('a; q=0, b'), array('b'), 
'->splitHttpAcceptHeader() removes values when q = 0 (as per the RFC)');
 
 // ->getRequestFormat() ->setRequestFormat()
 $t->diag('->getRequestFormat() ->setRequestFormat()');

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to