Skip to content

Commit 5717297

Browse files
committed
Fix issue with global tag prefix
* Add support for local tag prefixes.
1 parent f6abf31 commit 5717297

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

pkgs/yaml/lib/src/scanner.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,18 +918,37 @@ class Scanner {
918918
///
919919
/// %TAG !yaml! tag:yaml.org,2002: \n
920920
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
921+
///
922+
/// OR
923+
///
924+
/// %TAG !yaml! !dart \n
925+
/// ^^^^^^^^^^^^^^^^^
926+
///
921927
Token _scanTagDirectiveValue(LineScannerState start) {
922928
_skipBlanks();
923929

924-
var handle = _scanTagHandle(directive: true);
930+
final handle = _scanTagHandle(directive: true);
925931
if (!_isBlank) {
926932
throw YamlException('Expected whitespace.', _scanner.emptySpan);
927933
}
928934

929935
_skipBlanks();
930936

931-
var prefix = _scanTagUri();
932-
if (!_isBlankOrEnd) {
937+
/// Both tag uri and local tags can be used as prefixes.
938+
///
939+
/// See: https://yaml.org/spec/1.2.2/#6822-tag-prefixes
940+
var prefix = _scanner.peekChar() == EXCLAMATION
941+
? _scanTagHandle(directive: true, isPrefix: true)
942+
: '';
943+
944+
prefix += _scanTagUri(); // Readability's sake
945+
946+
if (prefix.isEmpty) {
947+
throw YamlException(
948+
'Expected a non-empty global tag prefix',
949+
_scanner.emptySpan,
950+
);
951+
} else if (!_isBlankOrEnd) {
933952
throw YamlException('Expected whitespace.', _scanner.emptySpan);
934953
}
935954

0 commit comments

Comments
 (0)