Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support reading of properties on implicit block mapping keys #561

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@ moment of adding them.
{ "foo,bar": ["baz"], "[object Object]": ["baz", "baz"] }
```

Also, reading of properties on implicit block mapping keys is not supported yet.
So, the following YAML document cannot be loaded.

``` yaml
&anchor foo:
foo: bar
*anchor: duplicate key
baz: bat
*anchor: duplicate key
```


js-yaml for enterprise
----------------------
Expand Down
18 changes: 15 additions & 3 deletions lib/js-yaml/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,12 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
detected = false,
ch;

if (state.blockMappingEntry < state.position) {
state.anchor = _anchor = null;
state.tag = _tag = null;
state.position = state.blockMappingEntry;
}

if (state.anchor !== null) {
state.anchorMap[state.anchor] = _result;
}
Expand Down Expand Up @@ -1292,7 +1298,8 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
typeQuantity,
type,
flowIndent,
blockIndent;
blockIndent,
ch;

if (state.listener !== null) {
state.listener('open', state);
Expand Down Expand Up @@ -1321,6 +1328,7 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
}
}

state.blockMappingEntry = state.position;
if (indentStatus === 1) {
while (readTagProperty(state) || readAnchorProperty(state)) {
if (skipSeparationSpace(state, true, -1)) {
Expand All @@ -1334,8 +1342,12 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
} else if (state.lineIndent < parentIndent) {
indentStatus = -1;
}
state.blockMappingEntry = state.position;
} else {
allowBlockCollections = false;
ch = state.input.charCodeAt(state.position);
if (ch === 0x7C/* | */ || ch === 0x3E/* > */) {
allowBlockCollections = false;
}
}
}
}
Expand All @@ -1356,7 +1368,7 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
if (indentStatus === 1) {
if (allowBlockCollections &&
(readBlockSequence(state, blockIndent) ||
readBlockMapping(state, blockIndent, flowIndent)) ||
readBlockMapping(state, state.blockMappingEntry - state.lineStart, flowIndent)) ||
readFlowCollection(state, flowIndent)) {
hasContent = true;
} else {
Expand Down
7 changes: 7 additions & 0 deletions test/samples-common/anchor-mapping-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
foo:{
foo:'bar'
}
};
2 changes: 2 additions & 0 deletions test/samples-common/anchor-mapping-key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
&anchor foo:
*anchor : bar
5 changes: 5 additions & 0 deletions test/samples-common/tag-mapping-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
TRUE: 1
};
1 change: 1 addition & 0 deletions test/samples-common/tag-mapping-key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!!str TRUE: 1
3 changes: 3 additions & 0 deletions test/samples-load-errors/duplicate-anchor-key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&anchor foo:
foo: bar,
*anchor: duplicate key