Skip to content

Commit

Permalink
bug #18844 [Yaml] fix exception contexts (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

[Yaml] fix exception contexts

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

9bdaba4 [Yaml] fix exception contexts
  • Loading branch information
fabpot committed May 23, 2016
2 parents 7830fa7 + 9bdaba4 commit 53b7236
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -88,7 +88,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
$isRef = $isInPlace = $isProcessed = false;
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#u', $this->currentLine, $values)) {
if ($context && 'mapping' == $context) {
throw new ParseException('You cannot define a sequence item when in a mapping');
throw new ParseException('You cannot define a sequence item when in a mapping', $this->getRealCurrentLineNb() + 1, $this->currentLine);
}
$context = 'sequence';

Expand Down Expand Up @@ -127,7 +127,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
}
} elseif (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))) {
if ($context && 'sequence' == $context) {
throw new ParseException('You cannot define a mapping item when in a sequence');
throw new ParseException('You cannot define a mapping item when in a sequence', $this->currentLineNb + 1, $this->currentLine);
}
$context = 'mapping';

Expand Down Expand Up @@ -214,7 +214,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
} else {
// multiple documents are not supported
if ('---' === $this->currentLine) {
throw new ParseException('Multiple documents are not supported.');
throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine);
}

// 1-liner optionally followed by newline(s)
Expand Down Expand Up @@ -449,7 +449,7 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport)
}

if (!array_key_exists($value, $this->refs)) {
throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLine);
throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLineNb + 1, $this->currentLine);
}

return $this->refs[$value];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -525,7 +525,7 @@ public function testShortcutKeyUnindentedCollectionException()

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Multiple documents are not supported.
* @expectedExceptionMessageRegExp /^Multiple documents are not supported.+/
*/
public function testMultipleDocumentsNotSupportedException()
{
Expand Down

0 comments on commit 53b7236

Please sign in to comment.