Skip to content

Commit

Permalink
Merge branch '2.1' into 2.2
Browse files Browse the repository at this point in the history
* 2.1:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: #7129

Conflicts:
	.travis.yml
	src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
	src/Symfony/Component/Routing/RouteCollection.php
  • Loading branch information
fabpot committed Mar 23, 2013
2 parents e24ce2f + 8ae7d98 commit 03fc97d
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 100 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -12,6 +12,7 @@ matrix:

before_script:
- echo '' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
- echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
- php src/Symfony/Component/Locale/Resources/data/build-data.php
- export USE_INTL_ICU_DATA_VERSION=1
Expand Up @@ -260,7 +260,7 @@ private function prepareParameters($parameters, $escape = true)
foreach ($parameters as $key => $value) {
if (is_array($value)) {
$value = $this->prepareParameters($value, $escape);
} elseif ($value instanceof Reference) {
} elseif ($value instanceof Reference || is_string($value) && 0 === strpos($value, '@')) {
$value = '@'.$value;
}

Expand Down
Expand Up @@ -290,7 +290,10 @@ private function resolveServices($value)
if (is_array($value)) {
$value = array_map(array($this, 'resolveServices'), $value);
} elseif (is_string($value) && 0 === strpos($value, '@')) {
if (0 === strpos($value, '@?')) {
if (0 === strpos($value, '@@')) {
$value = substr($value, 1);
$invalidBehavior = null;
} elseif (0 === strpos($value, '@?')) {
$value = substr($value, 2);
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
} else {
Expand All @@ -305,7 +308,9 @@ private function resolveServices($value)
$strict = true;
}

$value = new Reference($value, $invalidBehavior, $strict);
if (null !== $invalidBehavior) {
$value = new Reference($value, $invalidBehavior, $strict);
}
}

return $value;
Expand Down
Expand Up @@ -7,6 +7,7 @@
'FOO' => '%baz%',
'baz' => 'bar',
'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
)));

Expand Down
Expand Up @@ -37,6 +37,7 @@ protected function getDefaultParameters()
'foo' => '%baz%',
'baz' => 'bar',
'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',
'values' => array(
0 => true,
1 => false,
Expand Down
Expand Up @@ -7,6 +7,7 @@
<parameter key="foo">%baz%</parameter>
<parameter key="baz">bar</parameter>
<parameter key="bar">foo is %%foo bar</parameter>
<parameter key="escape">@escapeme</parameter>
<parameter key="values" type="collection">
<parameter>true</parameter>
<parameter>false</parameter>
Expand Down
Expand Up @@ -6,6 +6,7 @@ parameters:
- 0
- 1000.3
bar: foo
escape: @@escapeme
foo_bar: @foo_bar
MixedCase:
MixedCaseKey: value
Expand Up @@ -2,5 +2,6 @@ parameters:
foo: '%baz%'
baz: bar
bar: 'foo is %%foo bar'
escape: '@@escapeme'
values: [true, false, null, 0, 1000.3, 'true', 'false', 'null']

Expand Up @@ -84,7 +84,7 @@ public function testLoadParameters()
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services2.yml');
$this->assertEquals(array('foo' => 'bar', 'mixedcase' => array('MixedCaseKey' => 'value'), 'values' => array(true, false, 0, 1000.3), 'bar' => 'foo', 'foo_bar' => new Reference('foo_bar')), $container->getParameterBag()->all(), '->load() converts YAML keys to lowercase');
$this->assertEquals(array('foo' => 'bar', 'mixedcase' => array('MixedCaseKey' => 'value'), 'values' => array(true, false, 0, 1000.3), 'bar' => 'foo', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar')), $container->getParameterBag()->all(), '->load() converts YAML keys to lowercase');
}

public function testLoadImports()
Expand All @@ -99,7 +99,7 @@ public function testLoadImports()
$loader->load('services4.yml');

$actual = $container->getParameterBag()->all();
$expected = array('foo' => 'bar', 'values' => array(true, false), 'bar' => '%foo%', 'foo_bar' => new Reference('foo_bar'), 'mixedcase' => array('MixedCaseKey' => 'value'), 'imported_from_ini' => true, 'imported_from_xml' => true);
$expected = array('foo' => 'bar', 'values' => array(true, false), 'bar' => '%foo%', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar'), 'mixedcase' => array('MixedCaseKey' => 'value'), 'imported_from_ini' => true, 'imported_from_xml' => true);
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');

// Bad import throws no exception due to ignore_errors value.
Expand Down
Expand Up @@ -65,7 +65,11 @@ public function isCsrfTokenValid($intention, $token)
*/
protected function getSessionId()
{
if (!session_id()) {
if (version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_SESSION_NONE === session_status()) {
session_start();
}
} elseif (!session_id()) {
session_start();
}

Expand Down
Expand Up @@ -22,7 +22,8 @@ class DefaultCsrfProviderTest extends \PHPUnit_Framework_TestCase

public static function setUpBeforeClass()
{
@session_start();
ini_set('session.save_handler', 'files');
ini_set('session.save_path', sys_get_temp_dir());
}

protected function setUp()
Expand All @@ -37,20 +38,42 @@ protected function tearDown()

public function testGenerateCsrfToken()
{
session_start();

$token = $this->provider->generateCsrfToken('foo');

$this->assertEquals(sha1('SECRET'.'foo'.session_id()), $token);
}

public function testGenerateCsrfTokenOnUnstartedSession()
{
session_id('touti');

if (!version_compare(PHP_VERSION, '5.4', '>=')) {
$this->markTestSkipped('This test requires PHP >= 5.4');
}

$this->assertSame(PHP_SESSION_NONE, session_status());

$token = $this->provider->generateCsrfToken('foo');

$this->assertEquals(sha1('SECRET'.'foo'.session_id()), $token);
$this->assertSame(PHP_SESSION_ACTIVE, session_status());
}

public function testIsCsrfTokenValidSucceeds()
{
session_start();

$token = sha1('SECRET'.'foo'.session_id());

$this->assertTrue($this->provider->isCsrfTokenValid('foo', $token));
}

public function testIsCsrfTokenValidFails()
{
session_start();

$token = sha1('SECRET'.'bar'.session_id());

$this->assertFalse($this->provider->isCsrfTokenValid('foo', $token));
Expand Down
22 changes: 13 additions & 9 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1345,7 +1345,18 @@ public function getPreferredLanguage(array $locales = null)
return $locales[0];
}

$preferredLanguages = array_values(array_intersect($preferredLanguages, $locales));
$extendedPreferredLanguages = array();
foreach ($preferredLanguages as $language) {
$extendedPreferredLanguages[] = $language;
if (false !== $position = strpos($language, '_')) {
$superLanguage = substr($language, 0, $position);
if (!in_array($superLanguage, $preferredLanguages)) {
$extendedPreferredLanguages[] = $superLanguage;
}
}
}

$preferredLanguages = array_values(array_intersect($extendedPreferredLanguages, $locales));

return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
}
Expand Down Expand Up @@ -1379,21 +1390,14 @@ public function getLanguages()
for ($i = 0, $max = count($codes); $i < $max; $i++) {
if ($i == 0) {
$lang = strtolower($codes[0]);
// First segment of compound language codes
// is added to supported languages list
if (!in_array($lang, $this->languages)) {
$this->languages[] = $lang;
}
} else {
$lang .= '_'.strtoupper($codes[$i]);
}
}
}
}

if (!in_array($lang, $this->languages)) {
$this->languages[] = $lang;
}
$this->languages[] = $lang;
}

return $this->languages;
Expand Down
16 changes: 10 additions & 6 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -1013,6 +1013,14 @@ public function testGetPreferredLanguage()
$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
$this->assertEquals('en', $request->getPreferredLanguage(array('fr', 'en')));

$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8');
$this->assertEquals('en', $request->getPreferredLanguage(array('fr', 'en')));

$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, fr-fr; q=0.6, fr; q=0.5');
$this->assertEquals('en', $request->getPreferredLanguage(array('fr', 'en')));
}

public function testIsXmlHttpRequest()
Expand Down Expand Up @@ -1083,8 +1091,8 @@ public function testGetLanguages()

$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
$this->assertEquals(array('zh', 'en', 'en_US'), $request->getLanguages());
$this->assertEquals(array('zh', 'en', 'en_US'), $request->getLanguages());
$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');
Expand All @@ -1101,10 +1109,6 @@ public function testGetLanguages()
$request = new Request();
$request->headers->set('Accept-language', 'zh, i-cherokee; q=0.6');
$this->assertEquals(array('zh', 'cherokee'), $request->getLanguages());

$request = new Request();
$request->headers->set('Accept-language', 'en-us');
$this->assertEquals(array('en', 'en_US'), $request->getLanguages());
}

public function testGetRequestFormat()
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Process/Process.php
Expand Up @@ -131,8 +131,13 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin

$this->commandline = $commandline;
$this->cwd = $cwd;

// on windows, if the cwd changed via chdir(), proc_open defaults to the dir where php was started
if (null === $this->cwd && defined('PHP_WINDOWS_VERSION_BUILD')) {
// on gnu/linux, PHP builds with --enable-maintainer-zts are also affected
// @see : https://bugs.php.net/bug.php?id=51800
// @see : https://bugs.php.net/bug.php?id=50524

if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || defined('PHP_WINDOWS_VERSION_BUILD'))) {
$this->cwd = getcwd();
}
if (null !== $env) {
Expand Down
85 changes: 41 additions & 44 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -414,64 +414,61 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport)
*/
private function parseFoldedScalar($separator, $indicator = '', $indentation = 0)
{
$separator = '|' == $separator ? "\n" : ' ';
$text = '';

$notEOF = $this->moveToNextLine();

while ($notEOF && $this->isCurrentLineBlank()) {
$text .= "\n";

$notEOF = $this->moveToNextLine();
}

if (!$notEOF) {
return '';
}

if (!preg_match('#^(?P<indent>'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P<text>.*)$#u', $this->currentLine, $matches)) {
$this->moveToPreviousLine();

return '';
// determine indentation if not specified
if (0 === $indentation) {
if (preg_match('/^ +/', $this->currentLine, $matches)) {
$indentation = strlen($matches[0]);
}
}

$textIndent = $matches['indent'];
$previousIndent = 0;

$text .= $matches['text'].$separator;
while ($this->currentLineNb + 1 < count($this->lines)) {
$this->moveToNextLine();

if (preg_match('#^(?P<indent> {'.strlen($textIndent).',})(?P<text>.+)$#u', $this->currentLine, $matches)) {
if (' ' == $separator && $previousIndent != $matches['indent']) {
$text = substr($text, 0, -1)."\n";
$text = '';
if ($indentation > 0) {
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);

$isCurrentLineBlank = $this->isCurrentLineBlank();
while (
$notEOF && (
$isCurrentLineBlank ||
preg_match($pattern, $this->currentLine, $matches)
)
) {
if ($isCurrentLineBlank) {
$text .= substr($this->currentLine, $indentation);
} else {
$text .= $matches[1];
}
$previousIndent = $matches['indent'];

$text .= str_repeat(' ', $diff = strlen($matches['indent']) - strlen($textIndent)).$matches['text'].($diff ? "\n" : $separator);
} elseif (preg_match('#^(?P<text> *)$#', $this->currentLine, $matches)) {
$text .= preg_replace('#^ {1,'.strlen($textIndent).'}#', '', $matches['text'])."\n";
} else {
$this->moveToPreviousLine();

break;
// newline only if not EOF
if ($notEOF = $this->moveToNextLine()) {
$text .= "\n";
$isCurrentLineBlank = $this->isCurrentLineBlank();
}
}
} elseif ($notEOF) {
$text .= "\n";
}

if (' ' == $separator) {
// replace last separator by a newline
$text = preg_replace('/ (\n*)$/', "\n$1", $text);
if ($notEOF) {
$this->moveToPreviousLine();
}

switch ($indicator) {
case '':
$text = preg_replace('#\n+$#s', "\n", $text);
break;
case '+':
break;
case '-':
$text = preg_replace('#\n+$#s', '', $text);
break;
// replace all non-trailing single newlines with spaces in folded blocks
if ('>' === $separator) {
preg_match('/(\n*)$/', $text, $matches);
$text = preg_replace('/(?<!\n)\n(?!\n)/', ' ', rtrim($text, "\n"));
$text .= $matches[1];
}

// deal with trailing newlines as indicated
if ('' === $indicator) {
$text = preg_replace('/\n+$/s', "\n", $text);
} elseif ('-' === $indicator) {
$text = preg_replace('/\n+$/s', '', $text);
}

return $text;
Expand Down

0 comments on commit 03fc97d

Please sign in to comment.