Skip to content

Commit 73d3d40

Browse files
committed
feature symfony#23288 [Yaml] deprecate the !str tag (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] deprecate the !str tag | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | The tag specified in the YAML spec is actually !!str. Commits ------- 976b93a [Yaml] deprecate the !str tag
2 parents ccfc4da + 976b93a commit 73d3d40

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

UPGRADE-3.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ Validator
6161
Yaml
6262
----
6363

64+
* Support for the `!str` tag is deprecated, use the `!!str` tag instead.
65+
6466
* Using the non-specific tag `!` is deprecated and will have a different
6567
behavior in 4.0. Use a plain integer or `!!float` instead.

UPGRADE-4.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ Workflow
575575
Yaml
576576
----
577577

578+
* Support for the `!str` tag was removed, use the `!!str` tag instead.
579+
578580
* Starting an unquoted string with a question mark followed by a space
579581
throws a `ParseException`.
580582

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
3.4.0
55
-----
66

7+
* Support for the `!str` tag is deprecated, use the `!!str` tag instead.
8+
79
* Deprecated using the non-specific tag `!` as its behavior will change in 4.0.
810
It will force non-evaluating your values in 4.0. Use plain integers or `!!float` instead.
911

src/Symfony/Component/Yaml/Inline.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,11 @@ private static function evaluateScalar($scalar, $flags, $references = array())
609609
case $scalar[0] === '!':
610610
switch (true) {
611611
case 0 === strpos($scalar, '!str'):
612+
@trigger_error('Support for the !str tag is deprecated since version 3.4. Use the !!str tag instead.', E_USER_DEPRECATED);
613+
612614
return (string) substr($scalar, 5);
615+
case 0 === strpos($scalar, '!!str '):
616+
return (string) substr($scalar, 6);
613617
case 0 === strpos($scalar, '! '):
614618
@trigger_error('Using the non-specific tag "!" is deprecated since version 3.4 as its behavior will change in 4.0. It will force non-evaluating your values in 4.0. Use plain integers or !!float instead.', E_USER_DEPRECATED);
615619

src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ test: Various explicit families
592592
todo: true
593593
spec: 2.23
594594
yaml: |
595-
not-date: !str 2002-04-28
595+
not-date: !!str 2002-04-28
596596
picture: !binary |
597597
R0lGODlhDAAMAIQAAP//9/X
598598
17unp5WZmZgAAAOfn515eXv
@@ -932,7 +932,7 @@ deprecated: Using the non-specific tag "!" is deprecated since version 3.4 as it
932932
yaml: |
933933
integer: 12
934934
also int: ! "12"
935-
string: !str 12
935+
string: !!str 12
936936
php: |
937937
array( 'integer' => 12, 'also int' => 12, 'string' => '12' )
938938
---
@@ -964,7 +964,7 @@ documents: 2
964964
test: Type family under yaml.org
965965
yaml: |
966966
# The URI is 'tag:yaml.org,2002:str'
967-
- !str a Unicode string
967+
- !!str a Unicode string
968968
php: |
969969
array( 'a Unicode string' )
970970
---
@@ -1351,7 +1351,7 @@ yaml: |
13511351
13521352
second: 12 ## This is an integer.
13531353
1354-
third: !str 12 ## This is a string.
1354+
third: !!str 12 ## This is a string.
13551355
13561356
span: this contains
13571357
six spaces
@@ -1420,7 +1420,7 @@ yaml: |
14201420
# The following scalars
14211421
# are loaded to the
14221422
# string value '1' '2'.
1423-
- !str 12
1423+
- !!str 12
14241424
- '12'
14251425
- "12"
14261426
- "\

src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ php: |
5252
test: Forcing Strings
5353
brief: >
5454
Any YAML type can be forced into a string using the
55-
explicit !str method.
55+
explicit !!str method.
5656
yaml: |
57-
date string: !str 2001-08-01
58-
number string: !str 192
57+
date string: !!str 2001-08-01
58+
number string: !!str 192
5959
php: |
6060
array(
6161
'date string' => '2001-08-01',

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,4 +755,13 @@ public function getNotPhpCompatibleMappingKeyData()
755755
'float' => array('{0.25: "foo"}', array('0.25' => 'foo')),
756756
);
757757
}
758+
759+
/**
760+
* @group legacy
761+
* @expectedDeprecation Support for the !str tag is deprecated since version 3.4. Use the !!str tag instead.
762+
*/
763+
public function testDeprecatedStrTag()
764+
{
765+
$this->assertSame(array('foo' => 'bar'), Inline::parse('{ foo: !str bar }'));
766+
}
758767
}

0 commit comments

Comments
 (0)