Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f645ce8

Browse filesBrowse files
committed
[Yaml] parse custom tags for scalars
1 parent 587b2f7 commit f645ce8
Copy full SHA for f645ce8

File tree

4 files changed

+24
-10
lines changed
Filter options

4 files changed

+24
-10
lines changed

‎src/Symfony/Component/Yaml/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ CHANGELOG
44
4.0.0
55
-----
66

7+
* Inlined scalars starting with `!` will no longer be parsed as plain strings.
8+
Use the `Yaml::PARSE_CUSTOM_TAGS` flah to parse them as `TaggedValue` objects.
9+
Otherwise, detecting such strings will throw a `ParseException`.
710
* The behavior of the non-specific tag `!` is changed and now forces
811
non-evaluating your values.
912
* complex mappings will throw a `ParseException`

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,14 @@ private static function evaluateScalar($scalar, $flags, $references = array())
582582
case 0 === strpos($scalar, '!!binary '):
583583
return self::evaluateBinaryScalar(substr($scalar, 9));
584584
default:
585-
@trigger_error(sprintf('Using the unquoted scalar value "%s" is deprecated since version 3.3 and will be considered as a tagged value in 4.0. You must quote it.', $scalar), E_USER_DEPRECATED);
585+
$tagLength = strcspn($scalar, " \t\n", 1);
586+
$tag = substr($scalar, 1, $tagLength);
587+
588+
if (Yaml::PARSE_CUSTOM_TAGS & $flags) {
589+
return new TaggedValue($tag, substr($scalar, $tagLength + 2));
590+
}
591+
592+
throw new ParseException(sprintf('Tags support is not enabled. You must use the `Yaml::PARSE_CUSTOM_TAGS` flag to use "!%s".', $tag), self::$parsedLineNumber + 1, $scalar);
586593
}
587594

588595
// Optimize for returning strings.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,4 +703,13 @@ public function getNotPhpCompatibleMappingKeyData()
703703
'float' => array('{0.25: "foo"}', array('0.25' => 'foo')),
704704
);
705705
}
706+
707+
/**
708+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
709+
* @expectedExceptionMessage Tags support is not enabled. You must use the `Yaml::PARSE_CUSTOM_TAGS` flag to use "!iterator" at line 1 (near "!iterator foo").
710+
*/
711+
public function testCustomTagsDisabled()
712+
{
713+
Inline::parse('!iterator foo');
714+
}
706715
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/ParserTest.php
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,10 @@ public function taggedValuesProvider()
15661566
- !quz {foo: bar, quz: !bar {one: bar}}
15671567
YAML
15681568
),
1569+
'tagged scalar' => array(
1570+
new TaggedValue('iterator', 'foo'),
1571+
'!iterator foo',
1572+
),
15691573
);
15701574
}
15711575

@@ -1578,15 +1582,6 @@ public function testCustomTagsDisabled()
15781582
$this->parser->parse('!iterator [foo]');
15791583
}
15801584

1581-
/**
1582-
* @group legacy
1583-
* @expectedDeprecation Using the unquoted scalar value "!iterator foo" is deprecated since version 3.3 and will be considered as a tagged value in 4.0. You must quote it.
1584-
*/
1585-
public function testUnsupportedTagWithScalar()
1586-
{
1587-
$this->assertEquals('!iterator foo', $this->parser->parse('!iterator foo'));
1588-
}
1589-
15901585
/**
15911586
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
15921587
* @expectedExceptionMessage The built-in tag "!!foo" is not implemented.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.