Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
* 2.1:
  fixed CS
  added doc comments
  added doc comments
  [Validator] Updated swedish translation
  Update src/Symfony/Component/Validator/Resources/translations/validators.de.xlf
  [2.1] Exclude tests from zips via gitattributes
  [HttpKernel][Translator] Fixed type-hints
  Updated lithuanian validation translation
  [DomCrawler] Allows using multiselect through Form::setValues().
  [Translation] forced the catalogue to be regenerated when a resource is added (closes symfony/translation#1)
  Unit test for patched method OptionsResolver::validateOptionValues().
  validateOptionValues throw a notice if an allowed value is set and the corresponding option isn't.
  [Form] Hardened code of ViolationMapper against errors
  [HttpFoundation] Fixed #5611 - Request::splitHttpAcceptHeader incorrect result order.
  [Form] Fixed negative index access in PropertyPathBuilder
  Update src/Symfony/Component/Validator/Resources/translations/validators.ro.xlf

Conflicts:
	src/Symfony/Component/DomCrawler/Form.php
	src/Symfony/Component/Process/Process.php
  • Loading branch information
fabpot committed Oct 6, 2012
2 parents b412ca4 + 5f18e1d commit f01f68e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tests/ export-ignore
phpunit.xml.dist export-ignore
18 changes: 13 additions & 5 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1277,23 +1277,31 @@ public function splitHttpAcceptHeader($header)
}

$values = array();
$groups = array();
foreach (array_filter(explode(',', $header)) as $value) {
// Cut off any q-value that might come after a semi-colon
if (preg_match('/;\s*(q=.*$)/', $value, $match)) {
$q = (float) substr(trim($match[1]), 2);
$q = substr(trim($match[1]), 2);
$value = trim(substr($value, 0, -strlen($match[0])));
} else {
$q = 1;
}

$groups[$q][] = $value;
}

krsort($groups);

foreach ($groups as $q => $items) {
$q = (float) $q;

if (0 < $q) {
$values[trim($value)] = $q;
foreach ($items as $value) {
$values[trim($value)] = $q;
}
}
}

arsort($values);
reset($values);

return $values;
}

Expand Down
16 changes: 14 additions & 2 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ public function testGetCharsets()

$request = new Request();
$request->headers->set('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7');
$this->assertEquals(array('ISO-8859-1', '*', 'utf-8'), $request->getCharsets());
$this->assertEquals(array('ISO-8859-1', 'utf-8', '*'), $request->getCharsets());
}

public function testGetAcceptableContentTypes()
Expand All @@ -925,7 +925,7 @@ public function testGetAcceptableContentTypes()

$request = new Request();
$request->headers->set('Accept', 'application/vnd.wap.wmlscriptc, text/vnd.wap.wml, application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html, multipart/mixed, */*');
$this->assertEquals(array('multipart/mixed', '*/*', 'text/html', 'application/xhtml+xml', 'text/vnd.wap.wml', 'application/vnd.wap.xhtml+xml', 'application/vnd.wap.wmlscriptc'), $request->getAcceptableContentTypes());
$this->assertEquals(array('application/vnd.wap.wmlscriptc', 'text/vnd.wap.wml', 'application/vnd.wap.xhtml+xml', 'application/xhtml+xml', 'text/html', 'multipart/mixed', '*/*'), $request->getAcceptableContentTypes());
}

public function testGetLanguages()
Expand All @@ -938,6 +938,18 @@ public function testGetLanguages()
$this->assertEquals(array('zh', 'en_US', 'en'), $request->getLanguages());
$this->assertEquals(array('zh', 'en_US', 'en'), $request->getLanguages());

$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.6, en; q=0.8');
$this->assertEquals(array('zh', 'en', 'en_US'), $request->getLanguages()); // Test out of order qvalues

$request = new Request();
$request->headers->set('Accept-language', 'zh, en, en-us');
$this->assertEquals(array('zh', 'en', 'en_US'), $request->getLanguages()); // Test equal weighting without qvalues

$request = new Request();
$request->headers->set('Accept-language', 'zh; q=0.6, en, en-us; q=0.6');
$this->assertEquals(array('en', 'zh', 'en_US'), $request->getLanguages()); // Test equal weighting with qvalues

$request = new Request();
$request->headers->set('Accept-language', 'zh, i-cherokee; q=0.6');
$this->assertEquals(array('zh', 'cherokee'), $request->getLanguages());
Expand Down

0 comments on commit f01f68e

Please sign in to comment.