Skip to content

Commit

Permalink
Fix parsing of invalid block mappings
Browse files Browse the repository at this point in the history
close #418
  • Loading branch information
rlidwka committed Dec 29, 2020
1 parent e8cf6f6 commit f0f205b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Tags are now url-decoded in `load()` and url-encoded in `dump()`
(previously usage of custom non-ascii tags may have led to invalid YAML that can't be parsed).
- Anchors now work correctly with empty nodes, #301.
- Fix incorrect parsing of invalid block mapping syntax, #418.


## [3.14.1] - 2020-12-07
Expand Down
2 changes: 1 addition & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
ch = state.input.charCodeAt(state.position);
}

if (state.lineIndent > nodeIndent && (ch !== 0)) {
if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
throwError(state, 'bad indentation of a mapping entry');
} else if (state.lineIndent < nodeIndent) {
break;
Expand Down
11 changes: 11 additions & 0 deletions test/issues/0418.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';


const assert = require('assert');
const yaml = require('../../');


it('should error on invalid indentation in mappings', function () {
assert.throws(() => yaml.load('foo: "1" bar: "2"'), /bad indentation of a mapping entry/);
assert.throws(() => yaml.load('- "foo" - "bar"'), /bad indentation of a sequence entry/);
});

0 comments on commit f0f205b

Please sign in to comment.