bug #18844 [Yaml] fix exception contexts (xabbuh)
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
This commit is contained in:
commit
53b7236fa8
@ -88,7 +88,7 @@ class Parser
|
|||||||
$isRef = $isInPlace = $isProcessed = false;
|
$isRef = $isInPlace = $isProcessed = false;
|
||||||
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#u', $this->currentLine, $values)) {
|
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#u', $this->currentLine, $values)) {
|
||||||
if ($context && 'mapping' == $context) {
|
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';
|
$context = 'sequence';
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
} 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('"', "'")))) {
|
} 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) {
|
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';
|
$context = 'mapping';
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ class Parser
|
|||||||
} else {
|
} else {
|
||||||
// multiple documents are not supported
|
// multiple documents are not supported
|
||||||
if ('---' === $this->currentLine) {
|
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)
|
// 1-liner optionally followed by newline(s)
|
||||||
@ -449,7 +449,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists($value, $this->refs)) {
|
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];
|
return $this->refs[$value];
|
||||||
|
@ -525,7 +525,7 @@ EOF;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||||
* @expectedExceptionMessage Multiple documents are not supported.
|
* @expectedExceptionMessageRegExp /^Multiple documents are not supported.+/
|
||||||
*/
|
*/
|
||||||
public function testMultipleDocumentsNotSupportedException()
|
public function testMultipleDocumentsNotSupportedException()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user