diff --git a/CHANGELOG.md b/CHANGELOG.md index f44da6b3..e2cd11d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/loader.js b/lib/loader.js index f5adab25..b6dad5b3 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -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; diff --git a/test/issues/0418.js b/test/issues/0418.js new file mode 100644 index 00000000..94754dcf --- /dev/null +++ b/test/issues/0418.js @@ -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/); +});