From 4bd5165ece5040d682a8b2bad0fbf73b8880dd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Mon, 10 Oct 2022 14:49:36 +0200 Subject: [PATCH] fix resolving anchors across documents --- lib/loader.js | 2 +- test/samples-common/resolve-anchors-across-docs.js | 11 +++++++++++ test/samples-common/resolve-anchors-across-docs.yml | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/samples-common/resolve-anchors-across-docs.js create mode 100644 test/samples-common/resolve-anchors-across-docs.yml diff --git a/lib/loader.js b/lib/loader.js index 39f13f56..b62a54c8 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -1552,7 +1552,7 @@ function readDocument(state) { state.version = null; state.checkLineBreaks = state.legacy; state.tagMap = Object.create(null); - state.anchorMap = Object.create(null); + state.anchorMap = state.anchorMap || Object.create(null); while ((ch = state.input.charCodeAt(state.position)) !== 0) { skipSeparationSpace(state, true, -1); diff --git a/test/samples-common/resolve-anchors-across-docs.js b/test/samples-common/resolve-anchors-across-docs.js new file mode 100644 index 00000000..ecbae700 --- /dev/null +++ b/test/samples-common/resolve-anchors-across-docs.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = [ + { + foo: 'bar' + }, + { + foo: 'bar', + bar: 'baz' + } +]; diff --git a/test/samples-common/resolve-anchors-across-docs.yml b/test/samples-common/resolve-anchors-across-docs.yml new file mode 100644 index 00000000..50a198a9 --- /dev/null +++ b/test/samples-common/resolve-anchors-across-docs.yml @@ -0,0 +1,5 @@ +--- &default +foo: bar +--- +<< : *default +bar: baz \ No newline at end of file