Skip to content

Commit c02e836

Browse files
committed
Ensure a verbatim tag uri adheres to the spec
* A global tag uri prefix must with `tag:` if declared in verbatim. * Add more tests.
1 parent c4963fd commit c02e836

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pkgs/yaml/lib/src/scanner.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,16 +1068,14 @@ class Scanner {
10681068
} else {
10691069
tagUri = _scanTagUri(); // !<foo:uri>
10701070

1071-
// Expect !<foo:uri> to be !<tag:yaml.org,2002:*>
1072-
switch (tagUri.replaceFirst('tag:yaml.org,2002:', '')) {
1073-
case 'map' || 'seq' || 'str' || 'null' || 'bool' || 'int' || 'float':
1074-
break;
1075-
1076-
default:
1077-
throw YamlException(
1078-
'Invalid tag uri used as a verbatim tag',
1079-
_scanner.spanFrom(start),
1080-
);
1071+
/// Expect !<foo:uri> to be !<tag:*> (a global tag)
1072+
///
1073+
/// See: https://yaml.org/spec/1.2.2/#3212-tags
1074+
if (!tagUri.startsWith('tag:') || tagUri.substring(4).isEmpty) {
1075+
throw YamlException(
1076+
'Invalid tag uri used as a verbatim tag',
1077+
_scanner.spanFrom(start),
1078+
);
10811079
}
10821080
}
10831081

pkgs/yaml/test/yaml_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,8 @@ void main() {
11401140
test('[Example 6.25]', () {
11411141
expectYamlFails('- !<!> foo');
11421142
expectYamlFails('- !<\$:?> foo');
1143+
expectYamlFails('- !<tag:>'); // Incomplete verbatim tag uri
1144+
expectYamlFails('- !<improvised:tag>');
11431145
});
11441146

11451147
test('[Example 6.26]', () {

0 commit comments

Comments
 (0)