Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
* 2.1:
  [DependencyInjection] fixed the creation of synthetic services in ContainerBuilder
  [Security] PHPDoc in SecurityEvents
  Fix typos in README
  Added an error message in the DebugClassLoader when using / instead of \.
  KNOWN_ISSUES with php 5.3.16
  [FrameworkBundle] fixed Client::doRequest that must call its parent method (closes #6737)
  [Yaml] fixed ignored text when parsing an inlined mapping or sequence (closes #6786)
  [Yaml] fixed #6773
  [Yaml] fixed #6770
  bumped Symfony version to 2.1.8-DEV
  bumped Symfony version to 2.0.23-DEV

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Client.php
	src/Symfony/Component/HttpKernel/Kernel.php
  • Loading branch information
fabpot committed Jan 23, 2013
2 parents fd0ef38 + fef0f81 commit f5337ce
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 15 deletions.
21 changes: 14 additions & 7 deletions Inline.php
Expand Up @@ -52,21 +52,23 @@ public static function parse($value, $exceptionOnInvalidType = false, $objectSup
mb_internal_encoding('ASCII'); mb_internal_encoding('ASCII');
} }


$i = 0;
switch ($value[0]) { switch ($value[0]) {
case '[': case '[':
$result = self::parseSequence($value); $result = self::parseSequence($value, $i);
++$i;
break; break;
case '{': case '{':
$result = self::parseMapping($value); $result = self::parseMapping($value, $i);
++$i;
break; break;
default: default:
$i = 0;
$result = self::parseScalar($value, null, array('"', "'"), $i); $result = self::parseScalar($value, null, array('"', "'"), $i);
}


// some comment can end the scalar // some comments are allowed at the end
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i))); throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)));
}
} }


if (isset($mbEncoding)) { if (isset($mbEncoding)) {
Expand Down Expand Up @@ -413,6 +415,11 @@ private static function evaluateScalar($scalar)
$cast = intval($scalar); $cast = intval($scalar);


return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw); return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
$raw = $scalar;
$cast = intval($scalar);

return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
case 'true' === strtolower($scalar): case 'true' === strtolower($scalar):
return true; return true;
case 'false' === strtolower($scalar): case 'false' === strtolower($scalar):
Expand Down
9 changes: 3 additions & 6 deletions Parser.php
Expand Up @@ -190,8 +190,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
} }
} }
} else { } else {
// 1-liner followed by newline // 1-liner optionally followed by newline
if (2 == count($this->lines) && empty($this->lines[1])) { $lineCount = count($this->lines);
if (1 === $lineCount || (2 === $lineCount && empty($this->lines[1]))) {
try { try {
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport); $value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport);
} catch (ParseException $e) { } catch (ParseException $e) {
Expand Down Expand Up @@ -548,10 +549,6 @@ private function cleanup($value)
{ {
$value = str_replace(array("\r\n", "\r"), "\n", $value); $value = str_replace(array("\r\n", "\r"), "\n", $value);


if (!preg_match("#\n$#", $value)) {
$value .= "\n";
}

// strip YAML header // strip YAML header
$count = 0; $count = 0;
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count); $value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
Expand Down
21 changes: 19 additions & 2 deletions Tests/InlineTest.php
Expand Up @@ -19,7 +19,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
public function testParse() public function testParse()
{ {
foreach ($this->getTestsForParse() as $yaml => $value) { foreach ($this->getTestsForParse() as $yaml => $value) {
$this->assertEquals($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml)); $this->assertSame($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml));
} }
} }


Expand Down Expand Up @@ -92,6 +92,22 @@ public function testParseInvalidMappingKeyShouldThrowException()
Inline::parse($value); Inline::parse($value);
} }


/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testParseInvalidMappingShouldThrowException()
{
Inline::parse('[foo] bar');
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testParseInvalidSequenceShouldThrowException()
{
Inline::parse('{ foo: bar } bar');
}

public function testParseScalarWithCorrectlyQuotedStringShouldReturnString() public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
{ {
$value = "'don''t do somthin'' like that'"; $value = "'don''t do somthin'' like that'";
Expand All @@ -108,6 +124,7 @@ protected function getTestsForParse()
'false' => false, 'false' => false,
'true' => true, 'true' => true,
'12' => 12, '12' => 12,
'-12' => -12,
'"quoted string"' => 'quoted string', '"quoted string"' => 'quoted string',
"'quoted string'" => 'quoted string', "'quoted string'" => 'quoted string',
'12.30e+02' => 12.30e+02, '12.30e+02' => 12.30e+02,
Expand All @@ -117,7 +134,7 @@ protected function getTestsForParse()
'-.Inf' => log(0), '-.Inf' => log(0),
"'686e444'" => '686e444', "'686e444'" => '686e444',
'686e444' => 646e444, '686e444' => 646e444,
'123456789123456789' => '123456789123456789', '123456789123456789123456789123456789' => '123456789123456789123456789123456789',
'"foo\r\nbar"' => "foo\r\nbar", '"foo\r\nbar"' => "foo\r\nbar",
"'foo#bar'" => 'foo#bar', "'foo#bar'" => 'foo#bar',
"'foo # bar'" => 'foo # bar', "'foo # bar'" => 'foo # bar',
Expand Down
195 changes: 195 additions & 0 deletions Tests/ParserTest.php
Expand Up @@ -105,6 +105,201 @@ public function testEndOfTheDocumentMarker()
$this->assertEquals('foo', $this->parser->parse($yaml)); $this->assertEquals('foo', $this->parser->parse($yaml));
} }


public function getBlockChompingTests()
{
$tests = array();

$yaml = <<<'EOF'
foo: |-
one
two
bar: |-
one
two
EOF;
$expected = array(
'foo' => "one\ntwo",
'bar' => "one\ntwo",
);
$tests['Literal block chomping strip with 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 without 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 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 without trailing newline'] = array($expected, $yaml);

$yaml = <<<'EOF'
foo: |+
one
two
bar: |+
one
two
EOF;
$expected = array(
'foo' => "one\ntwo\n\n",
'bar' => "one\ntwo\n\n",
);
$tests['Literal block chomping keep with 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 keep without trailing newline'] = array($expected, $yaml);

$yaml = <<<'EOF'
foo: >-
one
two
bar: >-
one
two
EOF;
$expected = array(
'foo' => "one two",
'bar' => "one two",
);
$tests['Folded block chomping strip with trailing newline'] = array($expected, $yaml);

$yaml = <<<'EOF'
foo: >-
one
two
bar: >-
one
two
EOF;
$expected = array(
'foo' => "one two",
'bar' => "one two",
);
$tests['Folded block chomping strip without 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 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 without trailing newline'] = array($expected, $yaml);

$yaml = <<<'EOF'
foo: >+
one
two
bar: >+
one
two
EOF;
$expected = array(
'foo' => "one two\n\n",
'bar' => "one two\n\n",
);
$tests['Folded block chomping keep with 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 keep without trailing newline'] = array($expected, $yaml);

return $tests;
}

/**
* @dataProvider getBlockChompingTests
*/
public function testBlockChomping($expected, $yaml)
{
$this->assertSame($expected, $this->parser->parse($yaml));
}

public function testObjectSupportEnabled() public function testObjectSupportEnabled()
{ {
$input = <<<EOF $input = <<<EOF
Expand Down

0 comments on commit f5337ce

Please sign in to comment.