Merge branch '2.2'

* 2.2:
  #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: https://github.com/symfony/symfony/issues/7129
This commit is contained in:
Fabien Potencier 2013-03-23 09:06:49 +01:00
commit 77ec799751
17 changed files with 277 additions and 107 deletions

View File

@ -12,6 +12,7 @@ matrix:
before_script: before_script:
- echo '' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini - 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 - COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
- php src/Symfony/Component/Locale/Resources/data/build-data.php - php src/Symfony/Component/Locale/Resources/data/build-data.php
- export USE_INTL_ICU_DATA_VERSION=1 - export USE_INTL_ICU_DATA_VERSION=1

View File

@ -260,7 +260,7 @@ class YamlDumper extends Dumper
foreach ($parameters as $key => $value) { foreach ($parameters as $key => $value) {
if (is_array($value)) { if (is_array($value)) {
$value = $this->prepareParameters($value, $escape); $value = $this->prepareParameters($value, $escape);
} elseif ($value instanceof Reference) { } elseif ($value instanceof Reference || is_string($value) && 0 === strpos($value, '@')) {
$value = '@'.$value; $value = '@'.$value;
} }

View File

@ -290,7 +290,10 @@ class YamlFileLoader extends FileLoader
if (is_array($value)) { if (is_array($value)) {
$value = array_map(array($this, 'resolveServices'), $value); $value = array_map(array($this, 'resolveServices'), $value);
} elseif (is_string($value) && 0 === strpos($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); $value = substr($value, 2);
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE; $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
} else { } else {
@ -305,7 +308,9 @@ class YamlFileLoader extends FileLoader
$strict = true; $strict = true;
} }
$value = new Reference($value, $invalidBehavior, $strict); if (null !== $invalidBehavior) {
$value = new Reference($value, $invalidBehavior, $strict);
}
} }
return $value; return $value;

View File

@ -7,6 +7,7 @@ $container = new ContainerBuilder(new ParameterBag(array(
'FOO' => '%baz%', 'FOO' => '%baz%',
'baz' => 'bar', 'baz' => 'bar',
'bar' => 'foo is %%foo bar', 'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'), 'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
))); )));

View File

@ -37,6 +37,7 @@ class ProjectServiceContainer extends Container
'foo' => '%baz%', 'foo' => '%baz%',
'baz' => 'bar', 'baz' => 'bar',
'bar' => 'foo is %%foo bar', 'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',
'values' => array( 'values' => array(
0 => true, 0 => true,
1 => false, 1 => false,

View File

@ -7,6 +7,7 @@
<parameter key="foo">%baz%</parameter> <parameter key="foo">%baz%</parameter>
<parameter key="baz">bar</parameter> <parameter key="baz">bar</parameter>
<parameter key="bar">foo is %%foo bar</parameter> <parameter key="bar">foo is %%foo bar</parameter>
<parameter key="escape">@escapeme</parameter>
<parameter key="values" type="collection"> <parameter key="values" type="collection">
<parameter>true</parameter> <parameter>true</parameter>
<parameter>false</parameter> <parameter>false</parameter>

View File

@ -6,6 +6,7 @@ parameters:
- 0 - 0
- 1000.3 - 1000.3
bar: foo bar: foo
escape: @@escapeme
foo_bar: @foo_bar foo_bar: @foo_bar
MixedCase: MixedCase:
MixedCaseKey: value MixedCaseKey: value

View File

@ -2,5 +2,6 @@ parameters:
foo: '%baz%' foo: '%baz%'
baz: bar baz: bar
bar: 'foo is %%foo bar' bar: 'foo is %%foo bar'
escape: '@@escapeme'
values: [true, false, null, 0, 1000.3, 'true', 'false', 'null'] values: [true, false, null, 0, 1000.3, 'true', 'false', 'null']

View File

@ -84,7 +84,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services2.yml'); $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() public function testLoadImports()
@ -99,7 +99,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->load('services4.yml'); $loader->load('services4.yml');
$actual = $container->getParameterBag()->all(); $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'); $this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
// Bad import throws no exception due to ignore_errors value. // Bad import throws no exception due to ignore_errors value.

View File

@ -65,7 +65,11 @@ class DefaultCsrfProvider implements CsrfProviderInterface
*/ */
protected function getSessionId() 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(); session_start();
} }

View File

@ -22,7 +22,8 @@ class DefaultCsrfProviderTest extends \PHPUnit_Framework_TestCase
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
@session_start(); ini_set('session.save_handler', 'files');
ini_set('session.save_path', sys_get_temp_dir());
} }
protected function setUp() protected function setUp()
@ -37,13 +38,33 @@ class DefaultCsrfProviderTest extends \PHPUnit_Framework_TestCase
public function testGenerateCsrfToken() public function testGenerateCsrfToken()
{ {
session_start();
$token = $this->provider->generateCsrfToken('foo'); $token = $this->provider->generateCsrfToken('foo');
$this->assertEquals(sha1('SECRET'.'foo'.session_id()), $token); $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() public function testIsCsrfTokenValidSucceeds()
{ {
session_start();
$token = sha1('SECRET'.'foo'.session_id()); $token = sha1('SECRET'.'foo'.session_id());
$this->assertTrue($this->provider->isCsrfTokenValid('foo', $token)); $this->assertTrue($this->provider->isCsrfTokenValid('foo', $token));
@ -51,6 +72,8 @@ class DefaultCsrfProviderTest extends \PHPUnit_Framework_TestCase
public function testIsCsrfTokenValidFails() public function testIsCsrfTokenValidFails()
{ {
session_start();
$token = sha1('SECRET'.'bar'.session_id()); $token = sha1('SECRET'.'bar'.session_id());
$this->assertFalse($this->provider->isCsrfTokenValid('foo', $token)); $this->assertFalse($this->provider->isCsrfTokenValid('foo', $token));

View File

@ -1345,7 +1345,18 @@ class Request
return $locales[0]; 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]; return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
} }
@ -1379,11 +1390,6 @@ class Request
for ($i = 0, $max = count($codes); $i < $max; $i++) { for ($i = 0, $max = count($codes); $i < $max; $i++) {
if ($i == 0) { if ($i == 0) {
$lang = strtolower($codes[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 { } else {
$lang .= '_'.strtoupper($codes[$i]); $lang .= '_'.strtoupper($codes[$i]);
} }
@ -1391,9 +1397,7 @@ class Request
} }
} }
if (!in_array($lang, $this->languages)) { $this->languages[] = $lang;
$this->languages[] = $lang;
}
} }
return $this->languages; return $this->languages;

View File

@ -1013,6 +1013,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$request = new Request(); $request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6'); $request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
$this->assertEquals('en', $request->getPreferredLanguage(array('fr', 'en'))); $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() public function testIsXmlHttpRequest()
@ -1083,8 +1091,8 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$request = new Request(); $request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6'); $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_US', 'en'), $request->getLanguages());
$this->assertEquals(array('zh', 'en', 'en_US'), $request->getLanguages()); $this->assertEquals(array('zh', 'en_US', 'en'), $request->getLanguages());
$request = new Request(); $request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.6, en; q=0.8'); $request->headers->set('Accept-language', 'zh, en-us; q=0.6, en; q=0.8');
@ -1101,10 +1109,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$request = new Request(); $request = new Request();
$request->headers->set('Accept-language', 'zh, i-cherokee; q=0.6'); $request->headers->set('Accept-language', 'zh, i-cherokee; q=0.6');
$this->assertEquals(array('zh', 'cherokee'), $request->getLanguages()); $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() public function testGetRequestFormat()

View File

@ -131,8 +131,13 @@ class Process
$this->commandline = $commandline; $this->commandline = $commandline;
$this->cwd = $cwd; $this->cwd = $cwd;
// on windows, if the cwd changed via chdir(), proc_open defaults to the dir where php was started // 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(); $this->cwd = getcwd();
} }
if (null !== $env) { if (null !== $env) {

View File

@ -414,64 +414,61 @@ class Parser
*/ */
private function parseFoldedScalar($separator, $indicator = '', $indentation = 0) private function parseFoldedScalar($separator, $indicator = '', $indentation = 0)
{ {
$separator = '|' == $separator ? "\n" : ' ';
$text = '';
$notEOF = $this->moveToNextLine(); $notEOF = $this->moveToNextLine();
while ($notEOF && $this->isCurrentLineBlank()) {
$text .= "\n";
$notEOF = $this->moveToNextLine();
}
if (!$notEOF) { if (!$notEOF) {
return ''; return '';
} }
if (!preg_match('#^(?P<indent>'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P<text>.*)$#u', $this->currentLine, $matches)) { // determine indentation if not specified
$this->moveToPreviousLine(); if (0 === $indentation) {
if (preg_match('/^ +/', $this->currentLine, $matches)) {
return ''; $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";
}
$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;
} }
} }
if (' ' == $separator) { $text = '';
// replace last separator by a newline if ($indentation > 0) {
$text = preg_replace('/ (\n*)$/', "\n$1", $text); $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];
}
// newline only if not EOF
if ($notEOF = $this->moveToNextLine()) {
$text .= "\n";
$isCurrentLineBlank = $this->isCurrentLineBlank();
}
}
} elseif ($notEOF) {
$text .= "\n";
} }
switch ($indicator) { if ($notEOF) {
case '': $this->moveToPreviousLine();
$text = preg_replace('#\n+$#s', "\n", $text); }
break;
case '+': // replace all non-trailing single newlines with spaces in folded blocks
break; if ('>' === $separator) {
case '-': preg_match('/(\n*)$/', $text, $matches);
$text = preg_replace('#\n+$#s', '', $text); $text = preg_replace('/(?<!\n)\n(?!\n)/', ' ', rtrim($text, "\n"));
break; $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; return $text;

View File

@ -21,6 +21,21 @@ class DumperTest extends \PHPUnit_Framework_TestCase
protected $dumper; protected $dumper;
protected $path; protected $path;
protected $array = array(
'' => 'bar',
'foo' => '#bar',
'foo\'bar' => array(),
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
),
),
);
protected function setUp() protected function setUp()
{ {
$this->parser = new Parser(); $this->parser = new Parser();
@ -33,6 +48,33 @@ class DumperTest extends \PHPUnit_Framework_TestCase
$this->parser = null; $this->parser = null;
$this->dumper = null; $this->dumper = null;
$this->path = null; $this->path = null;
$this->array = null;
}
public function testSetIndentation()
{
$this->dumper->setIndentation(7);
$expected = <<<EOF
'': bar
foo: '#bar'
'foo''bar': { }
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo
EOF;
$this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0));
} }
public function testSpecifications() public function testSpecifications()
@ -63,27 +105,11 @@ class DumperTest extends \PHPUnit_Framework_TestCase
public function testInlineLevel() public function testInlineLevel()
{ {
// inline level
$array = array(
'' => 'bar',
'foo' => '#bar',
'foo\'bar' => array(),
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
),
),
);
$expected = <<<EOF $expected = <<<EOF
{ '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } } { '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
EOF; EOF;
$this->assertEquals($expected, $this->dumper->dump($array, -10), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($array, 0), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument');
$expected = <<<EOF $expected = <<<EOF
'': bar '': bar
@ -93,7 +119,7 @@ bar: [1, foo]
foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } }
EOF; EOF;
$this->assertEquals($expected, $this->dumper->dump($array, 1), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, 1), '->dump() takes an inline level argument');
$expected = <<<EOF $expected = <<<EOF
'': bar '': bar
@ -108,7 +134,7 @@ foobar:
foobar: { foo: bar, bar: [1, foo] } foobar: { foo: bar, bar: [1, foo] }
EOF; EOF;
$this->assertEquals($expected, $this->dumper->dump($array, 2), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, 2), '->dump() takes an inline level argument');
$expected = <<<EOF $expected = <<<EOF
'': bar '': bar
@ -127,7 +153,7 @@ foobar:
bar: [1, foo] bar: [1, foo]
EOF; EOF;
$this->assertEquals($expected, $this->dumper->dump($array, 3), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, 3), '->dump() takes an inline level argument');
$expected = <<<EOF $expected = <<<EOF
'': bar '': bar
@ -148,8 +174,8 @@ foobar:
- foo - foo
EOF; EOF;
$this->assertEquals($expected, $this->dumper->dump($array, 4), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, 4), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($array, 10), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, 10), '->dump() takes an inline level argument');
} }
public function testObjectSupportEnabled() public function testObjectSupportEnabled()

View File

@ -113,7 +113,6 @@ EOF;
foo: |- foo: |-
one one
two two
bar: |- bar: |-
one one
two two
@ -123,7 +122,24 @@ EOF;
'foo' => "one\ntwo", 'foo' => "one\ntwo",
'bar' => "one\ntwo", 'bar' => "one\ntwo",
); );
$tests['Literal block chomping strip with trailing newline'] = array($expected, $yaml); $tests['Literal block chomping strip with single trailing newline'] = array($expected, $yaml);
$yaml = <<<'EOF'
foo: |-
one
two
bar: |-
one
two
EOF;
$expected = array(
'foo' => "one\ntwo",
'bar' => "one\ntwo",
);
$tests['Literal block chomping strip with multiple trailing newlines'] = array($expected, $yaml);
$yaml = <<<'EOF' $yaml = <<<'EOF'
foo: |- foo: |-
@ -143,7 +159,6 @@ EOF;
foo: | foo: |
one one
two two
bar: | bar: |
one one
two two
@ -153,7 +168,24 @@ EOF;
'foo' => "one\ntwo\n", 'foo' => "one\ntwo\n",
'bar' => "one\ntwo\n", 'bar' => "one\ntwo\n",
); );
$tests['Literal block chomping clip with trailing newline'] = array($expected, $yaml); $tests['Literal block chomping clip with single trailing newline'] = array($expected, $yaml);
$yaml = <<<'EOF'
foo: |
one
two
bar: |
one
two
EOF;
$expected = array(
'foo' => "one\ntwo\n",
'bar' => "one\ntwo\n",
);
$tests['Literal block chomping clip with multiple trailing newlines'] = array($expected, $yaml);
$yaml = <<<'EOF' $yaml = <<<'EOF'
foo: | foo: |
@ -165,7 +197,7 @@ bar: |
EOF; EOF;
$expected = array( $expected = array(
'foo' => "one\ntwo\n", 'foo' => "one\ntwo\n",
'bar' => "one\ntwo\n", 'bar' => "one\ntwo",
); );
$tests['Literal block chomping clip without trailing newline'] = array($expected, $yaml); $tests['Literal block chomping clip without trailing newline'] = array($expected, $yaml);
@ -173,17 +205,33 @@ EOF;
foo: |+ foo: |+
one one
two two
bar: |+
one
two
EOF;
$expected = array(
'foo' => "one\ntwo\n",
'bar' => "one\ntwo\n",
);
$tests['Literal block chomping keep with single trailing newline'] = array($expected, $yaml);
$yaml = <<<'EOF'
foo: |+
one
two
bar: |+ bar: |+
one one
two two
EOF; EOF;
$expected = array( $expected = array(
'foo' => "one\ntwo\n\n", 'foo' => "one\ntwo\n\n",
'bar' => "one\ntwo\n\n", 'bar' => "one\ntwo\n\n",
); );
$tests['Literal block chomping keep with trailing newline'] = array($expected, $yaml); $tests['Literal block chomping keep with multiple trailing newlines'] = array($expected, $yaml);
$yaml = <<<'EOF' $yaml = <<<'EOF'
foo: |+ foo: |+
@ -195,7 +243,7 @@ bar: |+
EOF; EOF;
$expected = array( $expected = array(
'foo' => "one\ntwo\n", 'foo' => "one\ntwo\n",
'bar' => "one\ntwo\n", 'bar' => "one\ntwo",
); );
$tests['Literal block chomping keep without trailing newline'] = array($expected, $yaml); $tests['Literal block chomping keep without trailing newline'] = array($expected, $yaml);
@ -203,17 +251,33 @@ EOF;
foo: >- foo: >-
one one
two two
bar: >-
one
two
EOF;
$expected = array(
'foo' => "one two",
'bar' => "one two",
);
$tests['Folded block chomping strip with single trailing newline'] = array($expected, $yaml);
$yaml = <<<'EOF'
foo: >-
one
two
bar: >- bar: >-
one one
two two
EOF; EOF;
$expected = array( $expected = array(
'foo' => "one two", 'foo' => "one two",
'bar' => "one two", 'bar' => "one two",
); );
$tests['Folded block chomping strip with trailing newline'] = array($expected, $yaml); $tests['Folded block chomping strip with multiple trailing newlines'] = array($expected, $yaml);
$yaml = <<<'EOF' $yaml = <<<'EOF'
foo: >- foo: >-
@ -233,7 +297,6 @@ EOF;
foo: > foo: >
one one
two two
bar: > bar: >
one one
two two
@ -243,7 +306,24 @@ EOF;
'foo' => "one two\n", 'foo' => "one two\n",
'bar' => "one two\n", 'bar' => "one two\n",
); );
$tests['Folded block chomping clip with trailing newline'] = array($expected, $yaml); $tests['Folded block chomping clip with single trailing newline'] = array($expected, $yaml);
$yaml = <<<'EOF'
foo: >
one
two
bar: >
one
two
EOF;
$expected = array(
'foo' => "one two\n",
'bar' => "one two\n",
);
$tests['Folded block chomping clip with multiple trailing newlines'] = array($expected, $yaml);
$yaml = <<<'EOF' $yaml = <<<'EOF'
foo: > foo: >
@ -255,7 +335,7 @@ bar: >
EOF; EOF;
$expected = array( $expected = array(
'foo' => "one two\n", 'foo' => "one two\n",
'bar' => "one two\n", 'bar' => "one two",
); );
$tests['Folded block chomping clip without trailing newline'] = array($expected, $yaml); $tests['Folded block chomping clip without trailing newline'] = array($expected, $yaml);
@ -263,17 +343,33 @@ EOF;
foo: >+ foo: >+
one one
two two
bar: >+
one
two
EOF;
$expected = array(
'foo' => "one two\n",
'bar' => "one two\n",
);
$tests['Folded block chomping keep with single trailing newline'] = array($expected, $yaml);
$yaml = <<<'EOF'
foo: >+
one
two
bar: >+ bar: >+
one one
two two
EOF; EOF;
$expected = array( $expected = array(
'foo' => "one two\n\n", 'foo' => "one two\n\n",
'bar' => "one two\n\n", 'bar' => "one two\n\n",
); );
$tests['Folded block chomping keep with trailing newline'] = array($expected, $yaml); $tests['Folded block chomping keep with multiple trailing newlines'] = array($expected, $yaml);
$yaml = <<<'EOF' $yaml = <<<'EOF'
foo: >+ foo: >+
@ -285,7 +381,7 @@ bar: >+
EOF; EOF;
$expected = array( $expected = array(
'foo' => "one two\n", 'foo' => "one two\n",
'bar' => "one two\n", 'bar' => "one two",
); );
$tests['Folded block chomping keep without trailing newline'] = array($expected, $yaml); $tests['Folded block chomping keep without trailing newline'] = array($expected, $yaml);