Skip to content

tagMap is incorrectly cleared between reading documents, leading to exceptions #729

@hybridherbst

Description

@hybridherbst

Currently, state.tagMap is cleared on every document start:

js-yaml/lib/loader.js

Lines 1544 to 1554 in 0d3ca7a

function readDocument(state) {
var documentStart = state.position,
_position,
directiveName,
directiveArgs,
hasDirectives = false,
ch;
state.version = null;
state.checkLineBreaks = state.legacy;
state.tagMap = Object.create(null);

This is a bug – to the best of my understanding, this is valid YAML, where tags are declared at the start and then all the following documents can use those tags.

%YAML 1.1  
%TAG !u! tag:unity3d.com,2011:
--- !u!104 &render_settings # Document 1: Render Settings
RenderSettings:
  m_ObjectHideFlags: 0
  serializedVersion: 9
  m_Fog: 0
  m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
  m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
--- !u!1 &game_object_1 # Document 2: A Game Object
GameObject:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  serializedVersion: 6

It will result in an error while the second document is parsed:

YAML Error: undeclared tag handle "!u!"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions