Skip to content

Reject invalid local and global YAML tag text #58

Description

Context

YAML 1.2.2 requires verbatim and expanded tags to denote either local tags beginning with ! or global URI tags. Tags that cannot denote a type are invalid and should not be carried forward as unknown application data.

Official YAML 1.2.2 references:

Current State

The module validates tag character syntax and escape syntax and safely treats unknown tags as non-activating metadata. Some tags that are syntactically character-valid but not valid local/global tags can still be accepted as unknown tags.

Objective

Reject invalid tag text consistently across parsing, validation, formatting, and merging surfaces while preserving the safe behavior for valid unknown tags.

PowerShell Design Considerations

  • Invalid tags should produce stable, location-rich terminating errors for conversion commands and $false for Test-Yaml.
  • Valid unknown tags must remain safe and must not load .NET types or invoke PowerShell commands.
  • The validation should be a default conformance correction, not an opt-in parameter set.
  • Error records should be useful in pipeline automation, including line and column context.

Tasks

  • Reject verbatim tags that are empty, exactly !, or neither local tags nor global URI tags.
  • Reject shorthand tags whose expanded form is neither a local tag nor a global URI tag.
  • Preserve existing rejection of malformed percent escapes and invalid tag characters.
  • Keep valid unknown tags accepted under the safe unknown-tag policy.
  • Apply validation consistently to conversion, import, test, format, and merge surfaces.
  • Document compatibility impact for streams that were previously accepted incorrectly.

Benefits

  • Prevents invalid YAML representations from being normalized or projected.
  • Separates tag validity from native type availability.
  • Keeps the module safe while improving YAML 1.2.2 conformance.

Acceptance Criteria

  • !<!>, !<>, !<$:?>, and !<example> terminate with YamlInvalidTag on conversion/import surfaces.
  • Test-Yaml returns $false for invalid tag streams.
  • Format-Yaml and Merge-Yaml reject invalid tags rather than emitting them unchanged.
  • Valid local tags and valid global URI tags continue to parse successfully as unknown tags when no resolver is supplied.
  • Tests cover verbatim tags, shorthand expansion, malformed escapes, and valid unknown tags.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions