Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '2.1'

* 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...
commit f5337ce87cd1b92f7c70d2f8e3d4c36c1fb461f4 2 parents fd0ef38 + fef0f81
Fabien Potencier fabpot authored
Showing with 231 additions and 15 deletions.
  1. +14 −7 Inline.php
  2. +3 −6 Parser.php
  3. +19 −2 Tests/InlineTest.php
  4. +195 −0 Tests/ParserTest.php
21 Inline.php
View
@@ -52,21 +52,23 @@ public static function parse($value, $exceptionOnInvalidType = false, $objectSup
mb_internal_encoding('ASCII');
}
+ $i = 0;
switch ($value[0]) {
case '[':
- $result = self::parseSequence($value);
+ $result = self::parseSequence($value, $i);
+ ++$i;
break;
case '{':
- $result = self::parseMapping($value);
+ $result = self::parseMapping($value, $i);
+ ++$i;
break;
default:
- $i = 0;
$result = self::parseScalar($value, null, array('"', "'"), $i);
+ }
- // some comment can end the scalar
- if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
- throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)));
- }
+ // some comments are allowed at the end
+ if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
+ throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)));
}
if (isset($mbEncoding)) {
@@ -413,6 +415,11 @@ private static function evaluateScalar($scalar)
$cast = intval($scalar);
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):
return true;
case 'false' === strtolower($scalar):
9 Parser.php
View
@@ -190,8 +190,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
}
}
} else {
- // 1-liner followed by newline
- if (2 == count($this->lines) && empty($this->lines[1])) {
+ // 1-liner optionally followed by newline
+ $lineCount = count($this->lines);
+ if (1 === $lineCount || (2 === $lineCount && empty($this->lines[1]))) {
try {
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport);
} catch (ParseException $e) {
@@ -548,10 +549,6 @@ private function cleanup($value)
{
$value = str_replace(array("\r\n", "\r"), "\n", $value);
- if (!preg_match("#\n$#", $value)) {
- $value .= "\n";
- }
-
// strip YAML header
$count = 0;
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
21 Tests/InlineTest.php
View
@@ -19,7 +19,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
public function testParse()
{
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));
}
}
@@ -92,6 +92,22 @@ public function testParseInvalidMappingKeyShouldThrowException()
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()
{
$value = "'don''t do somthin'' like that'";
@@ -108,6 +124,7 @@ protected function getTestsForParse()
'false' => false,
'true' => true,
'12' => 12,
+ '-12' => -12,
'"quoted string"' => 'quoted string',
"'quoted string'" => 'quoted string',
'12.30e+02' => 12.30e+02,
@@ -117,7 +134,7 @@ protected function getTestsForParse()
'-.Inf' => log(0),
"'686e444'" => '686e444',
'686e444' => 646e444,
- '123456789123456789' => '123456789123456789',
+ '123456789123456789123456789123456789' => '123456789123456789123456789123456789',
'"foo\r\nbar"' => "foo\r\nbar",
"'foo#bar'" => 'foo#bar',
"'foo # bar'" => 'foo # bar',
195 Tests/ParserTest.php
View
@@ -105,6 +105,201 @@ public function testEndOfTheDocumentMarker()
$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()
{
$input = <<<EOF
Please sign in to comment.
Something went wrong with that request. Please try again.