Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e70ee8

Browse files
committed
trim spaces from unquoted scalar values
1 parent 3d011e0 commit 5e70ee8

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
286286
} elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
287287
$output = $match[1];
288288
$i += strlen($output);
289+
$output = trim($output);
289290
} else {
290291
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
291292
}

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
252252
{
253253
if (method_exists($this, 'expectExceptionMessage')) {
254254
$this->expectException(ParseException::class);
255-
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
255+
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
256256
} else {
257-
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
257+
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
258258
}
259259

260260
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
@@ -272,9 +272,9 @@ public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
272272
{
273273
if (method_exists($this, 'expectExceptionMessage')) {
274274
$this->expectException(ParseException::class);
275-
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
275+
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
276276
} else {
277-
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
277+
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
278278
}
279279

280280
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,10 @@ public function taggedValuesProvider()
16021602
- !quz {foo: bar, quz: !bar {one: bar}}
16031603
YAML
16041604
),
1605+
'spaces-around-tag-value-in-sequence' => array(
1606+
array(new TaggedValue('foo', 'bar')),
1607+
'[ !foo bar ]',
1608+
),
16051609
);
16061610
}
16071611

0 commit comments

Comments
 (0)