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: symfony/symfony#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 a573ce6 + b2f1a4d commit 41b5114
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 77 deletions.
85 changes: 41 additions & 44 deletions Parser.php
Original file line number Diff line number Diff line change
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
72 changes: 49 additions & 23 deletions Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ class DumperTest extends \PHPUnit_Framework_TestCase
protected $dumper;
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()
{
$this->parser = new Parser();
Expand All @@ -33,6 +48,33 @@ protected function tearDown()
$this->parser = null;
$this->dumper = 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()
Expand Down Expand Up @@ -63,27 +105,11 @@ public function testSpecifications()

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
{ '': 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($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, -10), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument');

$expected = <<<EOF
'': bar
Expand All @@ -93,7 +119,7 @@ public function testInlineLevel()
foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } }
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
'': bar
Expand All @@ -108,7 +134,7 @@ public function testInlineLevel()
foobar: { foo: bar, bar: [1, foo] }
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
'': bar
Expand All @@ -127,7 +153,7 @@ public function testInlineLevel()
bar: [1, foo]
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
'': bar
Expand All @@ -148,8 +174,8 @@ public function testInlineLevel()
- foo
EOF;
$this->assertEquals($expected, $this->dumper->dump($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, 4), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, 10), '->dump() takes an inline level argument');
}

public function testObjectSupportEnabled()
Expand Down
Loading

0 comments on commit 41b5114

Please sign in to comment.