Skip to content

Commit 38528f7

Browse files
committed
Fix minor issue in formatting error snippets
1 parent 4508352 commit 38528f7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function makeSnippet(mark, options) {
5252
lineEnds.push(match.index);
5353
lineStarts.push(match.index + match[0].length);
5454

55-
if (mark.position < match.index && foundLineNo < 0) {
55+
if (mark.position <= match.index && foundLineNo < 0) {
5656
foundLineNo = lineStarts.length - 2;
5757
}
5858
}

test/issues/0332.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,26 @@ it('Should format errors', function () {
1515
1 | "foo\u0001bar"
1616
-------------^`);
1717
}
18+
19+
try {
20+
yaml.load('*');
21+
} catch (err) {
22+
assert.strictEqual(err.toString(), `YAMLException: name of an alias node must contain at least one character (1:2)
23+
24+
1 | *
25+
------^`);
26+
}
27+
28+
try {
29+
yaml.load('foo:\n bar: 1\na');
30+
} catch (err) {
31+
// eslint-disable-next-line max-len
32+
assert.strictEqual(err.toString(), `YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key (4:1)
33+
34+
1 | foo:
35+
2 | bar: 1
36+
3 | a
37+
4 |
38+
-----^`);
39+
}
1840
});

0 commit comments

Comments
 (0)