@@ -12,6 +12,7 @@ import 'equality.dart';
1212import 'error_listener.dart' ;
1313import 'event.dart' ;
1414import 'parser.dart' ;
15+ import 'utils.dart' ;
1516import 'yaml_document.dart' ;
1617import 'yaml_exception.dart' ;
1718import 'yaml_node.dart' ;
@@ -125,9 +126,7 @@ class Loader {
125126
126127 /// Composes a sequence node.
127128 YamlNode _loadSequence (SequenceStartEvent firstEvent) {
128- if (firstEvent.tag != '!' &&
129- firstEvent.tag != null &&
130- firstEvent.tag != 'tag:yaml.org,2002:seq' ) {
129+ if (! isResolvedYamlTag (firstEvent.tag, 'seq' )) {
131130 throw YamlException ('Invalid tag for sequence.' , firstEvent.span);
132131 }
133132
@@ -147,9 +146,7 @@ class Loader {
147146
148147 /// Composes a mapping node.
149148 YamlNode _loadMapping (MappingStartEvent firstEvent) {
150- if (firstEvent.tag != '!' &&
151- firstEvent.tag != null &&
152- firstEvent.tag != 'tag:yaml.org,2002:map' ) {
149+ if (! isResolvedYamlTag (firstEvent.tag, 'map' )) {
153150 throw YamlException ('Invalid tag for mapping.' , firstEvent.span);
154151 }
155152
@@ -192,10 +189,22 @@ class Loader {
192189 var result = _parseNumber (scalar, allowInt: false );
193190 if (result != null ) return result;
194191 throw YamlException ('Invalid float scalar.' , scalar.span);
195- case 'tag:yaml.org,2002:str' :
196- return YamlScalar .internal (scalar.value, scalar);
197- default :
198- throw YamlException ('Undefined tag: ${scalar .tag }.' , scalar.span);
192+
193+ /// Represent partially as a string when custom tags are present. Any
194+ /// other yaml tag must be `!!str` .
195+ ///
196+ /// See: https://yaml.org/spec/1.2/spec.html#id2768011
197+ /// (PS: This is the YAML version this parser is based on)
198+ case String ? tag:
199+ {
200+ // Intentionally (quirky and) verbose. We want this condition to leak
201+ // for non-schema tags.
202+ if (! isResolvedYamlTag (tag, 'str' )) {
203+ throw YamlException ('Undefined tag: ${scalar .tag }.' , scalar.span);
204+ }
205+
206+ return YamlScalar .internal (scalar.value, scalar);
207+ }
199208 }
200209 }
201210
0 commit comments