Skip to content

Commit f0f205b

Browse files
committed
Fix parsing of invalid block mappings
close #418
1 parent e8cf6f6 commit f0f205b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4848
- Tags are now url-decoded in `load()` and url-encoded in `dump()`
4949
(previously usage of custom non-ascii tags may have led to invalid YAML that can't be parsed).
5050
- Anchors now work correctly with empty nodes, #301.
51+
- Fix incorrect parsing of invalid block mapping syntax, #418.
5152

5253

5354
## [3.14.1] - 2020-12-07

lib/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
11531153
ch = state.input.charCodeAt(state.position);
11541154
}
11551155

1156-
if (state.lineIndent > nodeIndent && (ch !== 0)) {
1156+
if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
11571157
throwError(state, 'bad indentation of a mapping entry');
11581158
} else if (state.lineIndent < nodeIndent) {
11591159
break;

test/issues/0418.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
4+
const assert = require('assert');
5+
const yaml = require('../../');
6+
7+
8+
it('should error on invalid indentation in mappings', function () {
9+
assert.throws(() => yaml.load('foo: "1" bar: "2"'), /bad indentation of a mapping entry/);
10+
assert.throws(() => yaml.load('- "foo" - "bar"'), /bad indentation of a sequence entry/);
11+
});

0 commit comments

Comments
 (0)