From 38528f7a7e46fc0a94d4154785344f40d70341e4 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 18 Dec 2020 14:01:25 +0300 Subject: [PATCH] Fix minor issue in formatting error snippets --- lib/snippet.js | 2 +- test/issues/0332.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/snippet.js b/lib/snippet.js index 13204807..c3669229 100644 --- a/lib/snippet.js +++ b/lib/snippet.js @@ -52,7 +52,7 @@ function makeSnippet(mark, options) { lineEnds.push(match.index); lineStarts.push(match.index + match[0].length); - if (mark.position < match.index && foundLineNo < 0) { + if (mark.position <= match.index && foundLineNo < 0) { foundLineNo = lineStarts.length - 2; } } diff --git a/test/issues/0332.js b/test/issues/0332.js index c3f0dc1b..14c32573 100644 --- a/test/issues/0332.js +++ b/test/issues/0332.js @@ -15,4 +15,26 @@ it('Should format errors', function () { 1 | "foo\u0001bar" -------------^`); } + + try { + yaml.load('*'); + } catch (err) { + assert.strictEqual(err.toString(), `YAMLException: name of an alias node must contain at least one character (1:2) + + 1 | * +------^`); + } + + try { + yaml.load('foo:\n bar: 1\na'); + } catch (err) { + // eslint-disable-next-line max-len + assert.strictEqual(err.toString(), `YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key (4:1) + + 1 | foo: + 2 | bar: 1 + 3 | a + 4 | +-----^`); + } });