Handle "!!" tag overriding.

This commit is contained in:
Ethiraric 2023-11-19 16:36:04 +01:00
parent ffed282a9f
commit 06a6fb34c1
2 changed files with 13 additions and 11 deletions

View file

@ -948,14 +948,20 @@ impl<T: Iterator<Item = char>> Parser<T> {
/// Resolve a tag from the handle and the suffix. /// Resolve a tag from the handle and the suffix.
fn resolve_tag(&self, mark: Marker, handle: &str, suffix: String) -> Result<Tag, ScanError> { fn resolve_tag(&self, mark: Marker, handle: &str, suffix: String) -> Result<Tag, ScanError> {
if handle == "!!" { if handle == "!!" {
// "!!" is a shorthand for "tag:yaml.org,2002:". // "!!" is a shorthand for "tag:yaml.org,2002:". However, that default can be
Ok(Tag { // overridden.
handle: "tag:yaml.org,2002:".to_string(), match self.tags.get("!!") {
suffix, Some(prefix) => Ok(Tag {
}) handle: prefix.to_string(),
suffix,
}),
None => Ok(Tag {
handle: "tag:yaml.org,2002:".to_string(),
suffix,
}),
}
} else if handle.is_empty() && suffix == "!" { } else if handle.is_empty() && suffix == "!" {
// "!" is a shorthand for "whatever would be the default". However, that // "!" introduces a local tag. Local tags may have their prefix overridden.
// default can be overridden.
match self.tags.get("") { match self.tags.get("") {
Some(prefix) => Ok(Tag { Some(prefix) => Ok(Tag {
handle: prefix.to_string(), handle: prefix.to_string(),

View file

@ -297,10 +297,6 @@ fn expected_events(expected_tree: &str) -> Vec<String> {
#[rustfmt::skip] #[rustfmt::skip]
static EXPECTED_FAILURES: &[&str] = &[ static EXPECTED_FAILURES: &[&str] = &[
// These seem to be API limited (not enough information on the event stream level)
// Cannot resolve tag namespaces
"P76L", // overriding the `!!` namespace!
// These seem to be plain bugs // These seem to be plain bugs
// Leading TAB in literal scalars // Leading TAB in literal scalars
"96NN-00", "96NN-00",