Skip to content

Commit fc738a6

Browse files
committed
[Yaml] Fix String offset cast error in Inline parser
1 parent d2cab32 commit fc738a6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Inline.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
458458

459459
// key
460460
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
461-
$i = strpos($mapping, ':', $i);
461+
462+
if (false === $i = strpos($mapping, ':', $i)) {
463+
break;
464+
}
462465

463466
if (!isset($mapping[$i + 1]) || ' ' !== $mapping[$i + 1]) {
464467
@trigger_error('Omitting the space after the colon that follows a mapping key definition is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);

Tests/InlineTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,4 +654,13 @@ public function getInvalidBinaryData()
654654
'misplaced equals character' => array('!!binary "SGVsbG8gd29ybG=Q"', '/The base64 encoded data \(.*\) contains invalid characters/'),
655655
);
656656
}
657+
658+
/**
659+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
660+
* @expectedExceptionMessage Malformed inline YAML string {this, is not, yaml}
661+
*/
662+
public function testStringOffsetCastError()
663+
{
664+
Inline::parse('{this, is not, yaml}');
665+
}
657666
}

0 commit comments

Comments
 (0)